Sunday, 15 May 2011

xml - How a value bind to another binded Node to get the TEXT which inside that Node -



xml - How a value bind to another binded Node to get the TEXT which inside that Node -

1i have xml , xslt files, want xslt auto value node in same xml file .

xslt line 68 know should not set way, no thought how pass value in key('description2-by-id', thanks

xml data

<data> <countrylist> <countryname code="aa" name="antarctica" ist="true"/> <countryname code="ab" name="abkhazia" ist="false"/> </countrylist> <description1list> <description1name description1id="1" recordtype="person">p1</description1name> <description1name description1id="2" recordtype="person">p2</description1name> <description1name description1id="1" recordtype="entity">e1</description1name> </description1list> <description2list> <description2name description2id="1" description1id="2">p21</description2name> <description2name description2id="2" description1id="2">p22</description2name> <description2name description2id="3" description1id="3">e11</description2name> </description2list> <description3list> <description3name description3id="1" description2id="1">p211</description3name> <description3name description3id="2" description2id="3">e111</description3name> </description3list> <referenceslist> <referencename code="9811" name="national list" description2id="1"/> </referenceslist> <records> <person id="752" date="15-oct-2013"> <country countrytype="bb"> <countryvalue>aa</countryvalue> </country> <descriptions> <description description1="1" description2="2" description3="1"/> <description description1="2"/> </descriptions> <references> <reference>9811</reference> </references> </person> <entity id="758" date="15-oct-2013"> <country countrytype="bc"> <countryvalue>ab</countryvalue> </country> <descriptions> <description description1="1" description2="3" description3="2"/> <description description1="3"/> </descriptions> </entity> </records> </data>

xslt

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:key name="country-by-code" match="countryname" use="@code"/> <xsl:key name="description1" match="description1name" use="concat(@description1id, '|', @recordtype)"/> <xsl:key name="description2-by-id" match="description2name" use="@description2id"/> <xsl:key name="description3-by-id" match="description3name" use="@description3id"/> <xsl:key name="reference-by-code" match="referencename" use="@code"/> <xsl:template match="/"> <html> <body> <table border="1"> <tr> <th>id</th> <th>date</th> <th>country</th> <th>description1</th> <th>description2</th> <th>description3</th> <th>reference</th> <th>referencename</th> <th>referencedescription2code</th> <th>referencedescription2</th> </tr> <xsl:apply-templates select="data/records/*"/> </table> </body> </html> </xsl:template> <xsl:template match="person | entity"> <xsl:variable name="varrrecord" select="."/> <xsl:for-each select="$varrrecord/country"> <xsl:variable name="varcountry" select="self::country"/> <xsl:for-each select="$varrrecord/descriptions/description | $varrrecord[not(descriptions/description)]"> <xsl:variable name="vardescription" select="self::description"/> <xsl:for-each select="$varrrecord/references/reference | $varrrecord[not(references/reference)]"> <xsl:variable name="varreference" select="self::reference"/> <tr> <td> <xsl:value-of select="$varrrecord/@id"/> </td> <td> <xsl:value-of select="$varrrecord/@date"/> </td> <td> [<xsl:value-of select="$varcountry/@countrytype"/>] <xsl:value-of select="key('country-by-code', $varcountry/countryvalue)/@name"/> [<xsl:value-of select="key('country-by-code', $varcountry/countryvalue)/@ist"/>] </td> <td> <xsl:value-of select="key('description1', concat($vardescription/@description1, '|', name($varrrecord)))"/> </td> <td> <xsl:value-of select="key('description2-by-id', $vardescription/@description2)"/> </td> <td> <xsl:value-of select="key('description3-by-id', $vardescription/@description3)"/> </td> <td> <xsl:value-of select="$varreference"/> </td> <td> <xsl:value-of select="key('reference-by-code', $varreference)/@name"/> </td> <td> <xsl:value-of select="key('reference-by-code', $varreference)/@description2id"/> </td> <td> <xsl:value-of select="key('description2-by-id', <xsl:value-of select="key('reference-by-code', $varreference)/@description2id"/>)"/> </td> </tr> </xsl:for-each> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet>

actual outcome is

|id |date |country |description1 |description2 |description3 |reference |referencename |referencedescription2code |referencedescription2| |752 |15-oct-2013 |[bb] antarctica [true] |p1 |p22 |p211 |9811 |national list |1 | | |752 |15-oct-2013 |[bb] antarctica [true] |p2 | | |9811 |national list |1 | | |758 |15-oct-2013 |[bc] abkhazia [false] |e1 |e11 |e111 | | | | | |758 |15-oct-2013 |[bc] abkhazia [false] | | | | | | | |

what expected outcome is

|id |date |country |description1 |description2 |description3 |reference |referencename |referencedescription2code |referencedescription2| |752 |15-oct-2013 |[bb] antarctica [true] |p1 |p22 |p211 |9811 |national list |1 |p21 | |752 |15-oct-2013 |[bb] antarctica [true] |p2 | | |9811 |national list |1 |p21 | |758 |15-oct-2013 |[bc] abkhazia [false] |e1 |e11 |e111 | | | | | |758 |15-oct-2013 |[bc] abkhazia [false] | | | | | | | |

again?

i afraid illustration not clear plenty (too many similar values) , there no explanation of logic(!), no more guess:

<td> <xsl:value-of select="key('description2-by-id', key('reference-by-code', $varreference)/@description2id)"/> </td>

what (1) @description2id value matching referencename, , (2) utilize description2name value via 'description2-by-id' key.

xml xslt

No comments:

Post a Comment