Search code examples
xsltnodeschildren

XSL printing child nodes


I have an xml file that has an address node that looks like

<address>
   <city>Anywhere</city>
   <state>NJ</city>
   <zip>12345</zip>
</address>

Right now, in the resulting xml file it prints out as

 Anywhere
 NJ
 12345

I'm trying to write a block in my xsl transform file to transform it to print as

 Anywhere, NJ 12345

But I'm not sure how to go about selecting the individual child nodes

I want to do something like:

<xsl:template match="address">
    <city>, <state> <zip>
</xsl:template>

Solution

  • <xsl:template match="address">
        <xsl:value-of select="city"/>, <xsl:value-of select="state"/> <xsl:value-of select="zip"/>
    </xsl:template>