Identity transformation problem... xml to xml transform
Posted: Fri Jul 07, 2006 11:26 pm
I already have a piece of code that will copy every attribute and node into a new xml document which is great! Here is the code:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
In my xml file the <radiobutton> nodes are missing an attribute called 'text' that needs to be added during the transform. The 'text' attribute must be copied from the <dataitem> node higher up in the xml.
A really simple example xml could look like this:
BEFORE:
<datasource id="LikertScale">
<dataitem text="Unimportant" value="1"/>
</datasource>
<datasource id="RandomScale">
<dataitem text="High Importance" value="1"/>
</datasource>
<radiobutton groupname="1" datasource="LikertScale" dataitem="1" showlabel="false" />
AFTER the transform:
<datasource id="LikertScale">
<dataitem text="Unimportant" value="1"/>
</datasource>
<datasource id="RandomScale">
<dataitem text="High Importance" value="1"/>
</datasource>
<radiobutton groupname="1" datasource="LikertScale" dataitem="1" showlabel="false" text="Unimportant" />
**The only difference is the new attribute called "text" has been added to the <radiobutton>. If the "text" attribute was already ready there in the <radiobutton> then it shouldn't get added.
The "text" attribute was copied from the <dataitem> text attribute higher up in the xml. In order to find the right "text" value, xsl must compare dataitem attribute in <radiobutton> with the value attribute in <dataitem>. XSL should only look at <dataitem> nodes that are nested inside the appropriate <datasource>. In my example <datasource> id attribute matches <radiobutton> datasource attribute ("LikertScale"). If I were to change the <radiobutton> datasource attribute to "RandomScale", then the "text" attribute that should be copied is "High Importance".
If anyone has the slightest clue how to grapple this problem, I would greatly appreciate any help!
Thanks![/b]
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
In my xml file the <radiobutton> nodes are missing an attribute called 'text' that needs to be added during the transform. The 'text' attribute must be copied from the <dataitem> node higher up in the xml.
A really simple example xml could look like this:
BEFORE:
<datasource id="LikertScale">
<dataitem text="Unimportant" value="1"/>
</datasource>
<datasource id="RandomScale">
<dataitem text="High Importance" value="1"/>
</datasource>
<radiobutton groupname="1" datasource="LikertScale" dataitem="1" showlabel="false" />
AFTER the transform:
<datasource id="LikertScale">
<dataitem text="Unimportant" value="1"/>
</datasource>
<datasource id="RandomScale">
<dataitem text="High Importance" value="1"/>
</datasource>
<radiobutton groupname="1" datasource="LikertScale" dataitem="1" showlabel="false" text="Unimportant" />
**The only difference is the new attribute called "text" has been added to the <radiobutton>. If the "text" attribute was already ready there in the <radiobutton> then it shouldn't get added.
The "text" attribute was copied from the <dataitem> text attribute higher up in the xml. In order to find the right "text" value, xsl must compare dataitem attribute in <radiobutton> with the value attribute in <dataitem>. XSL should only look at <dataitem> nodes that are nested inside the appropriate <datasource>. In my example <datasource> id attribute matches <radiobutton> datasource attribute ("LikertScale"). If I were to change the <radiobutton> datasource attribute to "RandomScale", then the "text" attribute that should be copied is "High Importance".
If anyone has the slightest clue how to grapple this problem, I would greatly appreciate any help!
Thanks![/b]