I have a XML file and a XSLT file as below
Check.xml
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>
Check.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="no"/>
<xsl:for-each select="/">
<xsl:choose>
<xsl:when test="country='USA'">
<xsl:copy-of select="CHK"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="*"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
When I try to transform it i get the below error
Error:XSLTProcessor::transformToXml() [<a href='xsltprocessor.transformtoxml'>xsltprocessor.transformtoxml</a>]: No stylesheet associated to this object
What Iam trying to do here is that check if the value is "USA" and if yes the replace USA with "CHK" String.
Iam not getting where I am going wrong or if Iam not using the correct syntax's. I am a newbie to XSLT and just got started with this. Any help is greatly appreciated!!! The output I am expecting is
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>**CHK**</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>
When this XSLT:
...is applied to the provided XML:
...the desired output is produced:
Explanation:
Identity Transform
- its job is to output all nodes and attributes from the source document to the result document as-is.<country>
element whose value is "USA". In this case, a new<country>
element is created and given the desired value.I recommend you look at this link for some great XSLT learning resources.