It only works if I have included the above templates, if I add other templates other than the above, then the translation does not work at all. None of the patterns are executed.
You are probably missing the namespace declaration for the book element. Example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:b="http://www.books.com/SRK" exclude-result-prefixes="b"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="b:name"> </xsl:template> </xsl:stylesheet>
Also, be sure to use the local-name() function to get the name of the element without the corresponding namespace.
Example
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:b="http://www.books.com/SRK" exclude-result-prefixes="b"> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:template match="b:input"> <xsl:element name="{local-name(.)}"> <xsl:apply-templates select="b:name"/> </xsl:element> </xsl:template> <xsl:template match="b:name"> <xsl:element name="{local-name()}"> <xsl:value-of select="."/> </xsl:element> <lhs> <xsl:apply-templates select="following-sibling::b:lhs/b:evaluate"/> </lhs> </xsl:template> <xsl:template match="b:evaluate"> Something to evaluate... </xsl:template> </xsl:stylesheet>
gets:
<?xml version="1.0" encoding="UTF-8"?> <input> <name>English</name> <lhs> Something to evaluate... </lhs> </input>
Second example
You can create a separate transformation called local-identity.xsl containing the @Dimitre solution. Then you can import it into your conversion. Since you have a namespace to match the elements, you must change all of your XPaths, including the prefix that you specify in the conversion, as in the following example:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:brl="http://www.xyz.com/BRL" exclude-result-prefixes="brl" version="1.0"> <xsl:import href="local-identity.xsl"/> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/brl:rule"> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet>
source share