--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/sysdefdowngrade/filter-module.xsl Wed Jan 20 15:03:03 2010 +0000
@@ -0,0 +1,110 @@
+<?xml version="1.0"?>
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt">
+ <xsl:output method="xml" indent="yes"/>
+
+
+<!-- filters can only return hide or show -->
+
+<!-- filter-only = item's @filter can only have items from the list
+ anything with no filters passes
+-->
+<xsl:template match="filter-only" mode="filter"><xsl:param name="item"/>
+ <xsl:if test="$item[@filter]">
+ <xsl:variable name="this" select="."/>
+ <xsl:variable name="my-filters">
+ <xsl:call-template name="filter-list">
+ <xsl:with-param name="f" select="$item/parent::component/@filter"/>
+ </xsl:call-template>
+ <xsl:call-template name="filter-list">
+ <xsl:with-param name="f" select="$item/@filter"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="match">
+ <xsl:for-each select="exslt:node-set($my-filters)/*">
+ <xsl:if test="not($this/*[name()=name(current()) and @v=current()/@v])">x</xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:if test="$match!=''">hide</xsl:if>
+ </xsl:if>
+</xsl:template>
+
+
+
+<!-- filter-has = item's @filter must have all filters in the list. ie it can have any other filters, but these must all be present
+-->
+<xsl:template match="filter-has" mode="filter"><xsl:param name="item"/>
+ <xsl:if test="$item[(self::component or self::unit) and not(unit/@filter or self::unit[not(../unit[@filter])])]">
+ <xsl:variable name="my-filters">
+ <xsl:call-template name="filter-list">
+ <xsl:with-param name="f" select="$item/parent::component/@filter"/>
+ </xsl:call-template>
+ <xsl:call-template name="filter-list">
+ <xsl:with-param name="f" select="$item/@filter"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="match">
+ <xsl:for-each select="*">
+ <!-- if(f in this) {return true} else if(!f in this) {return false} else {return !(f is positive)} -->
+ <xsl:choose>
+ <xsl:when test="exslt:node-set($my-filters)/*[name()=name(current()) and @v=current()/@v]"/> <!-- filter in item -->
+ <xsl:when test="exslt:node-set($my-filters)/*[name()!=name(current()) and @v=current()/@v]">x</xsl:when> <!-- !filter in item -->
+ <xsl:when test="self::filter">x</xsl:when> <!-- !(filter is positive) -->
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:if test="$match!=''">hide</xsl:if>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="filter-with" mode="filter"><xsl:param name="item"/>
+ <xsl:if test="$item[(self::component or self::unit) and not(unit/@filter or self::unit[not(../unit[@filter])])]">
+ <xsl:variable name="my-filters">
+ <xsl:call-template name="filter-list">
+ <xsl:with-param name="f" select="$item/parent::component/@filter"/>
+ </xsl:call-template>
+ <xsl:call-template name="filter-list">
+ <xsl:with-param name="f" select="$item/@filter"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="match">
+ <xsl:for-each select="*">
+ <xsl:if test="exslt:node-set($my-filters)/*[name()!=name(current()) and @v=current()/@v]">x</xsl:if> <!-- !filter in item -->
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:if test="$match!=''">hide</xsl:if>
+ </xsl:if>
+</xsl:template>
+
+
+
+<xsl:template name="filter-item"> <xsl:param name="f"/>
+ <!-- create an element for a given filter. If the filter's empty make nothing -->
+ <xsl:choose>
+ <xsl:when test="$f=''"/>
+ <xsl:when test="starts-with($f,'!')">
+ <not v="{substring($f,2)}"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <filter v="{$f}"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="filter-list"><xsl:param name="f"/>
+ <!-- turn a filter list into a set of elements (<filter> or <not>) with the attribute "v" containing the "absolute value" of the filter
+ filter="A,B,!C" becomes <filter v="A"/><filter v="B"/><not v="C"/>
+ -->
+ <xsl:choose>
+ <xsl:when test="contains($f,',')">
+ <xsl:call-template name="filter-item"><xsl:with-param name="f" select="normalize-space(substring-before($f,','))"/></xsl:call-template>
+ <xsl:call-template name="filter-list">
+ <xsl:with-param name="f" select="substring-after($f,',')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="filter-item"><xsl:with-param name="f" select="normalize-space($f)"/></xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/sysdefdowngrade/filtering.xsl Wed Jan 20 15:03:03 2010 +0000
@@ -0,0 +1,265 @@
+<?xml version="1.0"?>
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt">
+ <xsl:output method="xml" indent="yes"/>
+
+<!-- filter a sysdef (2.0 or 3.0 syntax)-->
+
+<xsl:param name="filter-type">only</xsl:param> <!-- only, has or with -->
+
+<xsl:param name="filter"/> <!-- comma-separated list -->
+
+<xsl:param name="addbuild" select="0"/> <!-- add a system build section that accepts everything -->
+
+
+<xsl:template match="node()|@*"><xsl:copy-of select="."/></xsl:template>
+<xsl:template match="*"><xsl:param name="data"/>
+ <xsl:copy>
+ <xsl:copy-of select="@*"/>
+ <xsl:apply-templates select="node()">
+ <xsl:with-param name="data" select="$data"/>
+ </xsl:apply-templates>
+ </xsl:copy>
+</xsl:template>
+
+<xsl:template match="component|unit"><xsl:param name="data"/> <!-- filterable items -->
+ <xsl:variable name="display">
+ <xsl:apply-templates select="$data" mode="filter">
+ <xsl:with-param name="item" select="current()"/>
+ </xsl:apply-templates>
+ </xsl:variable>
+
+ <xsl:if test="$display != 'hide' "> <!-- if hide, remove completely from the output-->
+ <xsl:copy>
+ <xsl:copy-of select="@*"/>
+ <xsl:apply-templates select="node()">
+ <xsl:with-param name="data" select="$data"/>
+ </xsl:apply-templates>
+ </xsl:copy>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="/SystemDefinition">
+ <xsl:variable name="f">
+ <xsl:element name="filter-{$filter-type}">
+ <xsl:call-template name="filter-list">
+ <xsl:with-param name="f" select="$filter"/>
+ </xsl:call-template>
+ </xsl:element>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="starts-with(@schema,'3.0')"/> <!-- no DTD needed for 3.0 sysdef -->
+ <xsl:when test="$addbuild">
+ <xsl:call-template name="DTD-bld"/> <!-- insert 2.0.1 DTD w/sysbuild parts-->
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="DTD"/> <!-- insert 2.0.1 DTD -->
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:copy>
+ <xsl:copy-of select="@*"/>
+ <xsl:variable name="content"> <!-- save content for potential further processing -->
+ <xsl:apply-templates select="node()">
+ <xsl:with-param name="data" select="exslt:node-set($f)/*"/>
+ </xsl:apply-templates>
+ </xsl:variable>
+ <!-- just output content as is. We could create a template to remove any filtered out items, but so far there's no compelling need -->
+ <xsl:copy-of select="$content"/>
+
+ <xsl:if test="$addbuild">
+ <SystemBuild schema="1.0.0">
+ <configuration name="any" description="text">
+ <xsl:attribute name="filter">
+ <xsl:for-each select="//@filter[not(.=following::*/@filter)]">
+ <xsl:value-of select="."/><xsl:if test="position()!=last()">,</xsl:if>
+ </xsl:for-each>
+ </xsl:attribute>
+ <xsl:for-each select="exslt:node-set($content)/systemModel/layer[descendant::unit]">
+ <!-- only include layers we know have units -->
+ <ref item="{@name}"/>
+ </xsl:for-each>
+ </configuration>
+ </SystemBuild>
+ </xsl:if>
+ </xsl:copy>
+</xsl:template>
+
+
+<xsl:include href="filter-module.xsl"/>
+
+<xsl:template name="DTD-bld">
+<xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE SystemDefinition [
+ <!ELEMENT SystemDefinition ( systemModel?, SystemBuild? )>
+ <!ATTLIST SystemDefinition
+ name CDATA #REQUIRED
+ schema CDATA #REQUIRED>
+ <!ELEMENT systemModel (layer+)>
+ <!ELEMENT layer (block* | collection*)*>
+ <!ATTLIST layer
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED
+ levels NMTOKENS #IMPLIED
+ span CDATA #IMPLIED>
+ <!ELEMENT block (subblock* | collection*)*>
+ <!ATTLIST block
+ levels NMTOKENS #IMPLIED
+ span CDATA #IMPLIED
+ level NMTOKEN #IMPLIED
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED>
+ <!ELEMENT subblock (collection)*>
+ <!ATTLIST subblock
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED>
+ <!ELEMENT collection (component)*>
+ <!ATTLIST collection
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED
+ level NMTOKEN #IMPLIED>
+ <!ELEMENT component (unit)*>
+ <!ATTLIST component
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED
+ deprecated CDATA #IMPLIED
+ introduced CDATA #IMPLIED
+ contract CDATA #IMPLIED
+ plugin (Y|N) "N"
+ filter CDATA #IMPLIED
+ class NMTOKENS #IMPLIED
+ supports CDATA #IMPLIED
+ purpose ( optional | mandatory | development ) "optional">
+ <!ELEMENT unit EMPTY>
+ <!ATTLIST unit
+ mrp CDATA #IMPLIED
+ filter CDATA #IMPLIED
+ bldFile CDATA #IMPLIED
+ root CDATA #IMPLIED
+ version NMTOKEN #IMPLIED
+ prebuilt NMTOKEN #IMPLIED
+ late (Y|N) #IMPLIED
+ priority CDATA #IMPLIED>
+ <!ELEMENT SystemBuild (option* | target+ | targetList+ | list+ | configuration+)*>
+ <!ATTLIST SystemBuild schema CDATA #REQUIRED>
+ <!ELEMENT list (ref+)>
+ <!ATTLIST list
+ name ID #REQUIRED
+ description CDATA #REQUIRED>
+ <!ELEMENT ref EMPTY>
+ <!ATTLIST ref item CDATA #REQUIRED>
+ <!ELEMENT targetList EMPTY>
+ <!ATTLIST targetList
+ name ID #REQUIRED
+ description CDATA #REQUIRED
+ target IDREFS #REQUIRED>
+ <!ELEMENT target EMPTY>
+ <!ATTLIST target
+ name ID #REQUIRED
+ abldTarget CDATA #REQUIRED
+ description CDATA #REQUIRED>
+ <!ELEMENT option EMPTY>
+ <!ATTLIST option
+ name ID #REQUIRED
+ abldOption CDATA #REQUIRED
+ description CDATA #REQUIRED
+ enable (Y | N ) #REQUIRED>
+ <!ELEMENT configuration (listRef+ | ref+ | task+)*>
+ <!ATTLIST configuration
+ name ID #REQUIRED
+ description CDATA #REQUIRED
+ filter CDATA #REQUIRED>
+ <!ELEMENT task (listRef* , (buildLayer | specialInstructions))>
+ <!ELEMENT listRef EMPTY>
+ <!ATTLIST listRef list CDATA #REQUIRED>
+ <!ELEMENT buildLayer EMPTY>
+ <!ATTLIST buildLayer
+ command CDATA #REQUIRED
+ targetList IDREFS #IMPLIED
+ unitParallel (Y | N ) #REQUIRED
+ targetParallel (Y | N ) "N">
+ <!ELEMENT specialInstructions EMPTY>
+ <!ATTLIST specialInstructions
+ name CDATA #REQUIRED
+ cwd CDATA #REQUIRED
+ root CDATA #IMPLIED
+ command CDATA #REQUIRED>
+]>
+]]></xsl:text>
+</xsl:template>
+
+<xsl:template name="DTD">
+<xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE SystemDefinition [
+<!ELEMENT SystemDefinition ( systemModel )>
+<!ATTLIST SystemDefinition
+ name CDATA #REQUIRED
+ schema CDATA #REQUIRED
+>
+<!-- all paths are relative to the environment variable specified by the root attribute, or SOURCEROOT if not. -->
+
+<!-- System Model Section of DTD -->
+<!ELEMENT systemModel (layer+)>
+
+<!ELEMENT layer (block* | collection*)*>
+<!-- Kernel Services, Base Services, OS Services, Etc -->
+<!ATTLIST layer
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED
+ levels NMTOKENS #IMPLIED
+ span CDATA #IMPLIED
+>
+
+<!ELEMENT block (subblock* | collection*)*>
+ <!-- Generic OS services, Comms Services, etc -->
+<!ATTLIST block
+ levels NMTOKENS #IMPLIED
+ span CDATA #IMPLIED
+ level NMTOKEN #IMPLIED
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED
+>
+
+<!ELEMENT subblock (collection)*>
+<!-- Cellular Baseband Services, Networking Services, etc -->
+<!ATTLIST subblock
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED
+>
+
+<!ELEMENT collection (component)*>
+<!-- Screen Driver, Content Handling, etc -->
+<!ATTLIST collection
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED
+ level NMTOKEN #IMPLIED
+>
+
+<!ELEMENT component (unit)*>
+<!-- contains units or is a package or prebuilt -->
+<!ATTLIST component
+ name CDATA #REQUIRED
+ long-name CDATA #IMPLIED
+ deprecated CDATA #IMPLIED
+ introduced CDATA #IMPLIED
+ contract CDATA #IMPLIED
+ plugin (Y|N) "N"
+ filter CDATA #IMPLIED
+ class NMTOKENS #IMPLIED
+ supports CDATA #IMPLIED
+ purpose ( optional | mandatory | development ) "optional"
+>
+
+<!ELEMENT unit EMPTY >
+<!-- must be buildable (bld.inf) -->
+<!-- bldFile may someday be removed in favour of mrp -->
+<!ATTLIST unit
+ mrp CDATA #IMPLIED
+ filter CDATA #IMPLIED
+ bldFile CDATA #IMPLIED
+ root CDATA #IMPLIED
+ version NMTOKEN #IMPLIED
+ prebuilt NMTOKEN #IMPLIED
+ late (Y|N) #IMPLIED
+ priority CDATA #IMPLIED
+>
+]>
+]]></xsl:text>
+</xsl:template>
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/sysdefdowngrade/joinsysdef-module.xsl Wed Jan 20 15:03:03 2010 +0000
@@ -0,0 +1,489 @@
+<?xml version="1.0"?>
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt">
+ <!-- save SF namespace as a constant to avoid the risk of typos-->
+ <xsl:variable name="defaultns">http://www.symbian.org/system-definition</xsl:variable>
+
+<!-- create a stand-alone sysdef from a linked set of fragments -->
+
+<xsl:template match="/*" mode="join">
+ <xsl:message terminate="yes">Cannot process this document</xsl:message>
+</xsl:template>
+
+
+<xsl:template match="/SystemDefinition[@schema='3.0.0' and count(*)=1]" mode="join">
+ <xsl:param name="origin" select="/.."/>
+ <xsl:param name="root"/>
+ <xsl:param name="filename"/>
+ <xsl:param name="namespaces"/>
+ <xsl:param name="data" select="/.."/>
+ <xsl:choose>
+ <xsl:when test="$origin"> <!-- this sysdef fragment was linked from a parent sysdef -->
+ <xsl:for-each select="*"> <!-- can be only one -->
+ <xsl:variable name="upid"><xsl:apply-templates select="$origin/@id" mode="my-id"/></xsl:variable> <!-- namespaceless ID of this in parent doc -->
+ <xsl:variable name="id"><xsl:apply-templates select="@id" mode="my-id"/></xsl:variable> <!-- namespaceless ID of this here -->
+ <xsl:variable name="upns"><xsl:apply-templates select="$origin/@id" mode="my-namespace"/></xsl:variable> <!-- ID's namespace in parent doc -->
+ <xsl:variable name="ns"><xsl:apply-templates select="@id" mode="my-namespace"/></xsl:variable> <!-- ID's namespace -->
+ <xsl:if test="$id!=$upid or $ns!=$upns">
+ <xsl:message terminate="yes">Linked ID "<xsl:value-of select="$id"/>" (<xsl:value-of select="$ns"/>) must match linking document "<xsl:value-of select="$upid"/>" (<xsl:value-of select="$upns"/>)</xsl:message>
+ </xsl:if>
+ <!-- copy any attributes not already defined (parent doc overrides child doc)-->
+ <xsl:for-each select="@*">
+ <xsl:variable name="n" select="name()"/>
+ <xsl:choose>
+ <xsl:when test="$n='id'"/> <!-- never copy this, always set -->
+ <xsl:when test="$origin/@*[name()=$n]"> <!-- don't copy if already set -->
+ <xsl:message>Cannot set "<xsl:value-of select="$n"/>", already set</xsl:message>
+ </xsl:when>
+ <xsl:when test="$n='before'">
+ <!-- ensure ns is correct (if any future attribtues will ever use an ID, process it here too)-->
+ <xsl:apply-templates select="." mode="join">
+ <xsl:with-param name="namespaces" select="$namespaces"/>
+ </xsl:apply-templates>
+ </xsl:when>
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- just copy anything else -->
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:copy-of select="../namespace::*[not(.=$namespaces)]"/> <!-- set any namespaces not already set (they should all alreayd be, but some XSLT processors are quirky) -->
+ <xsl:apply-templates select="$data" mode="overlay-attributes">
+ <xsl:with-param name="item" select="current()"/>
+ </xsl:apply-templates>
+ <xsl:variable name="content">
+ <xsl:apply-templates select="*|comment()" mode="join">
+ <xsl:with-param name="root" select="$root"/>
+ <xsl:with-param name="filename" select="$filename"/>
+ <xsl:with-param name="data" select="$data"/>
+ <xsl:with-param name="namespaces" select="$namespaces | ../namespace::*[not(.=$namespaces)]"/>
+ </xsl:apply-templates>
+ </xsl:variable>
+ <xsl:apply-templates select="." mode="is-content-filtered"> <!-- optionally add filtered="yes" if some content has been removed -->
+ <xsl:with-param name="content" select="$content"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="$data" mode="overlay-meta">
+ <xsl:with-param name="item" select="current()"/>
+ </xsl:apply-templates>
+ <xsl:copy-of select="$content"/>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:when test="function-available('exslt:node-set')"> <!-- this is the root element of a root sysdef -->
+ <!--try to put all namespaces in root element -->
+ <xsl:variable name="nss">
+ <!-- contains node set of namespaces to add to root element.
+ May panic if there are too many single-letter namespaces and this can't create a new one -->
+ <xsl:call-template name="needed-namespaces">
+ <xsl:with-param name="foundns">
+ <xsl:apply-templates select="//*[(self::component or self::collection or self::package or self::layer) and @href]" mode="scan-for-namespaces"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="ns" select="@id-namespace | namespace::* | exslt:node-set($nss)/*"/>
+ <xsl:copy><xsl:copy-of select="@*"/>
+ <xsl:apply-templates select="self::*[not(@id-namespace)]" mode="add-id-ns"/>
+ <xsl:for-each select="exslt:node-set($nss)/*"> <!-- add namespace definitions -->
+ <xsl:attribute name="xmlns:{name()}">
+ <xsl:value-of select="."/>
+ </xsl:attribute>
+ </xsl:for-each>
+ <!-- no need to call is-content-filtered, it never will be from this element -->
+ <xsl:apply-templates select="*|comment()" mode="join">
+ <xsl:with-param name="namespaces" select="$ns"/>
+ <xsl:with-param name="root" select="$root"/>
+ <xsl:with-param name="data" select="$data"/>
+ <xsl:with-param name="filename" select="$filename"/>
+ </xsl:apply-templates>
+ </xsl:copy>
+ </xsl:when>
+ <xsl:otherwise> <!-- can't handle node-set() so put the namespaces in the document instead of the root element-->
+ <xsl:variable name="ns" select="@id-namespace | namespace::*"/>
+ <xsl:copy><xsl:copy-of select="@*"/>
+ <!-- no need to call is-content-filtered, it never will be from this element -->
+ <xsl:apply-templates select="*|comment()" mode="join">
+ <xsl:with-param name="namespaces" select="$ns"/>
+ <xsl:with-param name="root" select="$root"/>
+ <xsl:with-param name="data" select="$data"/>
+ <xsl:with-param name="filename" select="$filename"/>
+ </xsl:apply-templates>
+ </xsl:copy>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="*" mode="scan-for-namespaces"/> <!-- just in case of errors, consider replacing by terminate -->
+<xsl:template match="*[@href and not(self::meta)]" mode="scan-for-namespaces">
+ <!-- produce a list of namespace-prefix namespace pairs separated by newlines, in reverse order found in documents
+ reverse order so we can try to use the first namespace prefix defined if it's available-->
+ <xsl:for-each select="document(@href,.)/*">
+ <xsl:apply-templates select="//*[(self::component or self::collection or self::package or self::layer) and @href]" mode="scan-for-namespaces"/>
+ <xsl:for-each select="//namespace::* | @id-namespace">
+ <xsl:value-of select="concat(name(),' ',.,'
')"/>
+ </xsl:for-each>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template name="needed-namespaces">
+ <xsl:param name="foundns"/>
+ <xsl:param name="usedpre"/>
+
+ <xsl:if test="foundns!=''">
+ <xsl:variable name="line" select="substring-before($foundns,'
')"/> <!-- always has trailing newline -->
+ <xsl:variable name="name" select="substring-after($line,' ')"/> <!-- namespace prefix -->
+ <xsl:variable name="remainder" select="substring-after($foundns,'
')"/>
+ <xsl:variable name="newprefix">
+ <xsl:if test="not(contains(concat('
',$remainder),concat('
',$line,'
'))) and
+ not(//namespace::*[.=$name] or @id-namespace[.=$name] or (not(@id-namespace) and $defaultns=$name))">
+ <xsl:apply-templates select="." mode="ns-prefix">
+ <xsl:with-param name="ns" select="$name"/>
+ <xsl:with-param name="pre" select="substring-before($line,' ')"/>
+ <xsl:with-param name="dontuse" select="$usedpre"/>
+ </xsl:apply-templates>
+ </xsl:if>
+ </xsl:variable>
+ <xsl:if test="$newprefix!=''">
+ <!-- can treat this as if it were a namespace node -->
+ <xsl:element name="{$newprefix}">
+ <xsl:value-of select="$name"/>
+ </xsl:element>
+ </xsl:if>
+ <xsl:if test="$remainder!=''">
+ <xsl:call-template name="needed-namespaces">
+ <xsl:with-param name="foundns" select="$remainder"/>
+ <xsl:with-param name="usedpre" select="concat($usedpre,' ',$newprefix,' ')"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="/SystemDefinition" mode="ns-prefix">
+ <!-- should be able to replace this with mechanism that uses the XSLT processor's own ability to generate namespaces -->
+ <xsl:param name="ns"/>
+ <xsl:param name="pre"/>
+ <xsl:param name="dontuse"/>
+ <xsl:param name="chars">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:param>
+ <xsl:variable name="name" select="substring(substring-after($ns,'http://www.'),1,1)"/>
+ <xsl:choose>
+ <xsl:when test="$pre!='' and $pre!='id-namespace' and not(//namespace::*[name()=$pre]) and not(contains($dontuse,concat(' ',$pre,' ')))">
+ <xsl:value-of select="$pre"/>
+ </xsl:when>
+ <xsl:when test="$ns='' and $chars=''">
+ <xsl:message terminate="yes">Cannot create namespace prefix for downstream default namespace</xsl:message>
+ </xsl:when>
+ <xsl:when test="$name!='' and not(contains($dontuse,concat(' ',$name,' ')))"><xsl:value-of select="$name"/></xsl:when>
+ <xsl:when test="namespace::*[name()=substring($chars,1,1)] or contains($dontuse,concat(' ',substring($chars,1,1),' '))">
+ <xsl:apply-templates mode="ns-prefix">
+ <xsl:with-param name="chars" select="substring($chars,2)"/>
+ </xsl:apply-templates>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="substring($chars,1,1)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
+<xsl:template match="unit" mode="join"> <xsl:param name="root"/><xsl:param name="filename"/><xsl:param name="data"/>
+ <xsl:variable name="display">
+ <xsl:apply-templates select="$data" mode="filter">
+ <xsl:with-param name="item" select="current()"/>
+ </xsl:apply-templates>
+ </xsl:variable>
+
+ <xsl:if test="$display != 'hide' "> <!-- if hide, remove completely from the output-->
+ <xsl:element name="{name()}">
+ <xsl:apply-templates select="@*" mode="join">
+ <xsl:with-param name="root" select="$root"/>
+ <xsl:with-param name="filename" select="$filename"/>
+ </xsl:apply-templates>
+ </xsl:element>
+ </xsl:if>
+</xsl:template>
+
+<!-- override mode="meta" to translate metadata sections. By default, include -->
+<xsl:template match="meta" priority="2"><xsl:param name="data"/>
+ <xsl:variable name="display">
+ <xsl:apply-templates select="$data" mode="filter">
+ <xsl:with-param name="item" select="current()"/>
+ </xsl:apply-templates>
+ </xsl:variable>
+
+ <xsl:if test="$display != 'hide' "> <!-- if hide, remove completely from the output-->
+ <xsl:apply-templates select="." mode="meta">
+ <xsl:with-param name="display" select="$display"/>
+ <xsl:with-param name="data" select="$data"/>
+ </xsl:apply-templates>
+ </xsl:if>
+</xsl:template>
+
+
+<xsl:template match="*" mode="join">
+ <xsl:param name="root"/><xsl:param name="filename"/><xsl:param name="namespaces"/><xsl:param name="data"/>
+ <!-- get attribtues from overlay -->
+ <!-- test for presence, if filtered out, just return -->
+ <!-- test for children, if it has some, but they're filtered out, either return or leave as empty, dependening on filter rule
+ if had items and now has none, options:
+ still has meta: keep / delete
+ still has comments: keep / delete
+ -->
+
+ <xsl:variable name="display">
+ <xsl:apply-templates select="$data" mode="filter">
+ <xsl:with-param name="item" select="current()"/>
+ </xsl:apply-templates>
+ </xsl:variable>
+
+ <xsl:if test="$display != 'hide' "> <!-- if hide, remove completely from the output-->
+
+ <xsl:variable name="href">
+ <xsl:apply-templates select="." mode="link">
+ <xsl:with-param name="data" select="$data"/>
+ </xsl:apply-templates>
+ </xsl:variable>
+
+
+ <xsl:element name="{name()}"> <!-- use this instead of <copy> so xalan doesn't add extra wrong namespaces -->
+ <xsl:apply-templates select="@*" mode="join">
+ <xsl:with-param name="namespaces" select="$namespaces"/>
+ </xsl:apply-templates>
+ <xsl:if test="$display != '' ">
+ <!-- custom attribute to indicate how this is to be represented. Blank indicates normal, hide removes from the output (see above), anything else is put in the attribute -->
+ <xsl:attribute name="display"><xsl:value-of select="$display"/></xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates select="$data" mode="overlay-attributes">
+ <xsl:with-param name="item" select="current()"/>
+ </xsl:apply-templates>
+ <xsl:choose>
+ <xsl:when test="$href !='' ">
+ <xsl:variable name="origin" select="."/>
+ <xsl:apply-templates select="document($href,.)/*" mode="join">
+ <xsl:with-param name="origin" select="$origin"/>
+ <xsl:with-param name="data" select="$data"/>
+ <xsl:with-param name="namespaces" select="$namespaces"/>
+ <xsl:with-param name="filename">
+ <xsl:call-template name="joinpath">
+ <xsl:with-param name="file" select="$filename"/>
+ <xsl:with-param name="rel" select="$href"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ <xsl:with-param name="root">
+ <xsl:value-of select="$root"/>/<xsl:call-template name="lastbefore">
+ <xsl:with-param name="string" select="$href"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="content">
+ <xsl:apply-templates select="*|comment()" mode="join">
+ <xsl:with-param name="root" select="$root"/>
+ <xsl:with-param name="filename" select="$filename"/>
+ <xsl:with-param name="namespaces" select="$namespaces"/>
+ <xsl:with-param name="data" select="$data"/>
+ </xsl:apply-templates>
+ </xsl:variable>
+ <xsl:apply-templates select="." mode="is-content-filtered"> <!-- add filtered="yes" if some content has been removed -->
+ <xsl:with-param name="content" select="$content"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="$data" mode="overlay-meta">
+ <xsl:with-param name="item" select="current()"/>
+ </xsl:apply-templates>
+ <xsl:copy-of select="$content"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:element>
+ </xsl:if>
+</xsl:template>
+
+<!-- By default, do nothing. Can override template to add filtered="yes" if need to track what's a placeholder and what's been filtered
+ implement with param name="content"
+-->
+<xsl:template mode="is-content-filtered" match="*" priority="-2"/>
+
+
+<xsl:template match="@mrp[starts-with(.,'/')] | @bldFile[starts-with(.,'/')] | @base[starts-with(.,'/')]" mode="join">
+ <xsl:copy-of select="."/>
+</xsl:template>
+
+<xsl:template match="@mrp|@bldFile|@base" mode="join"> <xsl:param name="root"/><xsl:param name="filename"/>
+ <xsl:attribute name="{name()}">
+ <xsl:call-template name="joinpath">
+ <xsl:with-param name="file" select="$filename"/>
+ <xsl:with-param name="rel" select="."/>
+ </xsl:call-template>
+ </xsl:attribute>
+</xsl:template>
+
+
+<xsl:template match="@href" mode="join"/> <!--never copy this into the generated doc, that's the whole point of this module -->
+
+<xsl:template match="@*" mode="my-namespace"> <!-- the namespace of an ID -->
+ <xsl:choose>
+ <xsl:when test="contains(.,':')">
+ <xsl:value-of select="ancestor::*/namespace::*[name()=substring-before(current(),':')]"/>
+ </xsl:when>
+ <xsl:when test="/SystemDefinition/@id-namespace">
+ <xsl:value-of select="/SystemDefinition/@id-namespace"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$defaultns"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
+<xsl:template match="@*" mode="my-id"> <!-- the ID with namespace prefix removed -->
+ <xsl:choose>
+ <xsl:when test="contains(.,':')">
+ <xsl:value-of select="substring-after(.,':')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="@id|@before" mode="join">
+ <xsl:param name="namespaces"/>
+ <!-- this will change the namespace prefixes for all IDs to match the root document -->
+ <xsl:variable name="ns">
+ <xsl:apply-templates select="." mode="my-namespace"/>
+ </xsl:variable>
+ <xsl:if test="$ns=''">
+ <xsl:message terminate="yes">Could not find namespace for <xsl:value-of select="."/>
+ </xsl:message>
+ </xsl:if>
+ <xsl:variable name="prefix" select="name($namespaces[.=$ns])"/>
+ <xsl:attribute name="{name()}">
+ <xsl:choose>
+ <xsl:when test="$prefix = 'id-namespace' or (not($namespaces[name()='id-prefix']) and $ns=$defaultns)"/> <!-- it's the default namespace, no prefix -->
+ <xsl:when test="$prefix='' and contains(.,':')">
+ <!-- complex: copy id and copy namespace (namespace should be copied already)-->
+ <xsl:value-of select="."/>
+ </xsl:when>
+ <xsl:when test="$prefix='' and $ns=$defaultns"/> <!-- no prefix and it's the default -->
+ <xsl:when test="$prefix!=''"> <!-- just change the prefix -->
+ <xsl:value-of select="concat($prefix,':')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message terminate="yes">Error</xsl:message>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:apply-templates select="." mode="my-id"/>
+ </xsl:attribute>
+</xsl:template>
+
+
+
+<xsl:template match="@*|comment()" mode="join"><xsl:copy-of select="."/></xsl:template>
+
+
+<!-- path handling follows -->
+
+ <xsl:template name="lastbefore"><xsl:param name="string"/><xsl:param name="substr" select="'/'"/>
+ <xsl:if test="contains($string,$substr)">
+ <xsl:value-of select="substring-before($string,$substr)"/>
+ <xsl:if test="contains(substring-after($string,$substr),$substr)">
+ <xsl:value-of select="$substr"/>
+ </xsl:if>
+ <xsl:call-template name="lastbefore">
+ <xsl:with-param name="string" select="substring-after($string,$substr)"/>
+ <xsl:with-param name="substr" select="$substr"/>
+ </xsl:call-template>
+ </xsl:if>
+</xsl:template>
+
+ <xsl:template name="joinpath"><xsl:param name="file"/><xsl:param name="rel"/>
+ <xsl:call-template name="reducepath">
+ <xsl:with-param name="file">
+ <xsl:call-template name="lastbefore">
+ <xsl:with-param name="string" select="$file"/>
+ </xsl:call-template>
+ <xsl:text>/</xsl:text>
+ <xsl:value-of select="$rel"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+<xsl:template name="reducepath"><xsl:param name="file"/>
+ <xsl:call-template name="reducedotdotpath">
+ <xsl:with-param name="file">
+ <xsl:call-template name="reducedotpath">
+ <xsl:with-param name="file" select="$file"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="reducedotdotpath"><xsl:param name="file"/>
+ <xsl:choose>
+ <xsl:when test="starts-with($file,'../')">
+ <xsl:text>../</xsl:text>
+ <xsl:call-template name="reducedotdotpath">
+ <xsl:with-param name="file" select="substring($file,4)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="contains($file,'/../')">
+ <xsl:call-template name="reducepath">
+ <xsl:with-param name="file">
+ <xsl:call-template name="lastbefore">
+ <xsl:with-param name="string" select="substring-before($file,'/../')"/>
+ </xsl:call-template>
+ <xsl:text>/</xsl:text>
+ <xsl:value-of select="substring-after($file,'/../')"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise><xsl:value-of select="$file"/></xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+<xsl:template name="reducedotpath"><xsl:param name="file"/>
+ <xsl:choose>
+ <xsl:when test="starts-with($file,'./')">
+ <xsl:call-template name="reducedotpath">
+ <xsl:with-param name="file" select="substring($file,3)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="contains($file,'/./')">
+ <xsl:call-template name="reducepath">
+ <xsl:with-param name="file">
+ <xsl:value-of select="substring-before($file,'/./')"/>
+ <xsl:text>/</xsl:text>
+ <xsl:value-of select="substring-after($file,'/./')"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise><xsl:value-of select="$file"/></xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+<!-- overridable templates follow -->
+
+
+<xsl:template match="*" mode="filter" priority="-9"/> <!-- by default show -->
+<xsl:template match="*" mode="overlay-attributes" priority="-9"/> <!-- by default do nothing -->
+<xsl:template match="*" mode="overlay-meta" priority="-9"/> <!-- by default do nothing -->
+<xsl:template match="/SystemDefinition" mode="add-id-ns" priority="-9"/> <!-- some tools may have an easier job if this were always present, but, by default, assume it can just stay implied -->
+
+<xsl:template match="*" mode="link" priority="-1"> <!-- can be overriden to allow custom changes to href values -->
+<xsl:value-of select="@href"/>
+</xsl:template>
+
+
+<xsl:template match="*" mode="meta" priority="-9"><xsl:param name="data"/><xsl:param name="display"/>
+ <xsl:element name="{name()}">
+ <xsl:copy-of select="@*[name()!='href']"/> <!-- copy all attributes as is, always drop href -->
+ <xsl:choose>
+ <xsl:when test="$display='local' and @href and contains(@href,':') and not(starts-with(@href,'file:'))">
+ <!-- non-local URL: only want local URLs, so keep href as is-->
+ <xsl:copy-of select="@href"/>
+ </xsl:when>
+ <xsl:when test="@href">
+ <xsl:copy-of select="document(@href,.)/*"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="*|comment()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:element>
+</xsl:template>
+
+</xsl:stylesheet>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/sysdefdowngrade/joinsysdef.xsl Wed Jan 20 15:03:03 2010 +0000
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="xml" indent="yes"/>
+<!-- create a stand-alone sysdef from a linked set of fragments -->
+
+<xsl:param name="path">/os/deviceplatformrelease/foundation_system/system_model/system_definition.xml</xsl:param>
+
+<xsl:template match="/*">
+ <xsl:apply-templates select="." mode="join"/>
+</xsl:template>
+
+
+<xsl:template match="/SystemDefinition[systemModel]">
+<xsl:apply-templates select="." mode="join">
+ <xsl:with-param name="filename" select="$path"/>
+</xsl:apply-templates>
+</xsl:template>
+
+
+
+
+<xsl:include href="joinsysdef-module.xsl"/>
+
+</xsl:stylesheet>