xslt - Match conditionally upon current node value -
given following xml:
<current> <login_name>jd</login_name> </current> <people> <person> <first>john</first> <last>doe</last> <login_name>jd</login_name> </preson> <person> <first>pierre</first> <last>spring</last> <login_name>ps</login_name> </preson> </people>
how can "john doe" within current/login matcher?
i tried following:
<xsl:template match="current/login_name"> <xsl:value-of select="../people/first[login_name = .]"/> <xsl:text> </xsl:text> <xsl:value-of select="../people/last[login_name = .]"/> </xsl:template>
i'd define key index people:
<xsl:key name="people" match="person" use="login_name" />
using key here keeps code clean, might find helpful efficiency if you're having retrieve <person>
elements based on <login_name>
child.
i'd have template returned formatted name of given <person>
:
<xsl:template match="person" mode="name"> <xsl:value-of select="concat(first, ' ', last)" /> </xsl:template>
and i'd do:
<xsl:template match="current/login_name"> <xsl:apply-templates select="key('people', .)" mode="name" /> </xsl:template>
Comments
Post a Comment