xslt select a node value based on the value of another node -
i being tasked creating csv file using xslt produce information. far have need however, there 1 bit struggling per example below.
<issuesexport xmlns="http://www.mynamesapce.co.uk/import"> <materials> <material> <code>wb821</code> <name>concentrate</name> </material> <material> <code>wb820</code> <name>additive</name> </material> </materials> <issues> <issue> <formulacode>test</formulacode> <materialbatch> <materialcode>wb821</materialcode> <batchnumber>sdfsd</batchnumber> <ismanualaddbatch>false</ismanualaddbatch> <isfinished>true</isfinished> <weight>0</weight> <cost>0</cost> </materialbatch> <issuebatchnumber>df34323</issuebatchnumber> </issue>
what need grab name //material/name issue/materialbatch/materialcode = material/code.
my current xslt looks this
<xsl:if test="i:materialbatch/i:materialcode=//i:material/i:code"> <xsl:value-of select="//i:materials/i:material/i:name"/> </xsl:if>
which evaluating true , giving result of concentrate.
i grateful if tell me going wrong
thank you
your test returns true, because comparing 2 node-sets - , such test returns true if 1 of nodes in set matches node in set b.
the result "concentrate" because
<xsl:value-of select="//i:materials/i:material/i:name"/>
returns value of first node of set matching select
expression.
xslt has build-in mechanism looking referenced values. in order use it, start defining key @ top-level of stylesheet:
<xsl:key name="material-bycode" match="i:material" use="i:code" />
then, context of issue
can use:
<xsl:value-of select="key('material-by-code', i:materialbatch/i:materialcode)/i:name"/>
to retrieve corresponding name.
Comments
Post a Comment