Re: Extend XML file attributes using XSLT
"Christian Rühl" <[email protected]> Fri, 23 Nov 2007 00:15:27 -0800 (PST)
| Newsgroups | gmane.comp.mozilla.devel.layout.xslt |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <[email protected]> |
new day, new problem here... :(
i have two xml files with some similar attributes. i want to copy
specific content (namely attributes) from one xml file to the other.
to show you of what i'm talking, heres how my archive and my product
tree xml files look like (very abstract):
--- archive.xml ---
<Common name="..." path="..." />
<Common ... />
<Glue name="..." path="..." />
<Glue ... />
<Mtds name="..." path="..." />
<Mtds ... />
<Mtds ... />
<ARCHIVE>
<Module moduleName="moduleA" variant="2" subsystem="subsystemA"
path="..." textConvention="..." />
<Module moduleName="moduleX" variant="17" subsystem="subsystemB"
path="..." textConvention="..." />
<Product cid="9000" subsystem="subsystemD" path="..."
textConvention="..." />
</ARCHIVE>
--- prodtree.xml ---
<PRODUCT_TREE productName="TestProduct" softwareVersion="1.0"
description="...">
<TopLevelComponent topLevelModule="Mab" cid="1200" description="...">
<Module selectedModule="moduleA" instance="12"/>
<Component topLevelModule="Mxy" cid="9000" description="...">
<SubComponent topLevelModule="Mxy" cid="5500" description="...">
<Module selectedModule="moduleX" instance="1"/>
</SubComponent>
</Component>
</TopLevelComponent>
</PRODUCT_TREE>
------------------------------------------
hint:
PRODUCT_TREE/selectedModule == ARCHIVE/moduleName
------------------------------------------
what i want to do now is to extend the prodtree.xml as said below:
- for all <*Component> nodes: check if there is a <Product> node in
archive.xml with the same cid? if so: copy all other attributes from
that node.
- for all <Module> nodes: check if there is a <Module> node in
archive.xml with the selectedModule == moduleName? if so: copy all
other attributes from that node.
so that the outcome looks like this:
--- result.xml ---
<PRODUCT_TREE productName="TestProduct" softwareVersion="1.0"
description="...">
<TopLevelComponent topLevelModule="Mab" cid="1200" description="...">
<Module selectedModule="moduleA" instance="12" variant="2"
subsystem="subsystemA" path="..." textConvention="..."/>
<Component topLevelModule="Mxy" cid="9000" subsystem="subsystemD"
path="..." description="...">
...
</PRODUCT_TREE>
------------------------------------------
i really hope you can help me again! thats how far i came by now:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="archive"/>
<xsl:template match="/">
<TOP>
<xsl:for-each select="TopLevelComponent">
<TopLevelComponent cid="{@cid}" topLevelModule="{@topLevelModule}"
softwareVersion="{@softwareVersion}">
<xsl:variable name="cid" select="string(@cid)"/>
<xsl:for-each select="document($archive)">
<xsl:copy-of select="cid($cid)/*"/>
</xsl:for-each>
</TopLevelComponent>
</xsl:for-each>
</TOP>
</xsl:template>
</xsl:stylesheet>
doesn't work of course... :(