Subject: Re: [xsl] Replacing values in the input file with values from a second file From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Tue, 07 Apr 2009 15:29:45 +0200 |
Hi Everyone,
I have a seemingly simple transformation project, but there is a piece of the puzzle that I'm missing. Maybe the solution isn't so simple, after all. :-)
Here is my input file.
<topic id="A"> <title>Menus</title> <topic id="AB"> <title>Menu AB Details</title> <body> <p id="AB1"> <uicontrol conref="AB1a"/> </p> <p id="AB2"> <uicontrol conref="AB2a"/> <uicontrol conref="AB2b"/> </p> </body> </topic> </topic>
For each uicontrol element, I'd like to substitute the element value in a second file, whose id attribute value corresponds to the conref value in the first file.
Here is the second file (navigation-labels.xml):
<topic id ="navigation-labels"> <title>Navigation Labels</title> <body> <p><uicontrol id="AB1a">Oranges</uicontrol></p> <p><uicontrol id="AB2a">Apples</uicontrol></p> <p><uicontrol id="AB3b">Bananas</uicontrol></p> </body> </topic>
Here is the output I'm trying to produce:
<topic id="A"> <title>Menus</title> <topic id="AB"> <title>Menu AB Details</title> <body> <p id="AB1"> <uicontrol>Oranges</uicontrol> </p> <p id="AB2"> <uicontrol>Apples</uicontrol> <uicontrol>Bananas</uicontrol> </p> </body> </topic> </topic>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="uicontrol"> <xsl:variable name="ref" select="@conref"/> <xsl:copy> <xsl:for-each select="$uic-doc"> <xsl:value-of select="key('uic', $ref)"/> </xsl:for-each> </xsl:copy> </xsl:template>
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Martin Honnen http://JavaScript.FAQTs.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Replacing values in the input, Mark Peters | Thread | Re: [xsl] Replacing values in the i, Andrew Welch |
[xsl] Replacing values in the input, Mark Peters | Date | Re: [xsl] Replacing values in the i, Andrew Welch |
Month |