I have two simple templates listed below operating on some sample data also listed below:
<?xml version="1.0" encoding="utf-8?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="Gallery/Tab/ImageGroup/Image">
<xsl:apply-templates select="imageText" />
</xsl:template>
<xsl:template match="imageText">
<h2><xsl:value-of select="." /></h2>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<Gallery name="My Gallery">
<Tab tabID="imageDivTab0" height="500" name="Team Wear">
<ImageGroup>
<Image>
<imageName>Challenge-Badge.jpg</imageName>
<imageURL>images/gallery/small/Tab1/</imageURL>
<imageText>Challenge Badge</imageText>
</Image>
</ImageGroup>
</Tab>
</Gallery>
When the processor runs I get the expected result (imageText being displayed) if I comment out the first template I get everything being displayed (imageName, imageURL and image Text).
Is this because the second template is trying to match 'imageText' without the proper context, i.e. it is using the root node, so it displays everything.
I am fairly new to this so any help would be much appreciated.
Cheers
There are several built-in template rules.
Reference: http://www.w3.org/TR/xslt#built-in-rule
In your case applied templates are:
<xsl:template match="*|/">
<xsl:apply-templates/>
</xsl:template>
and
<xsl:template match="text()|@*">
<xsl:value-of select="."/>
</xsl:template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With