posted 15 years ago
I want to transform the following simple XML, replacing test1 with test2 and test2 with test3.
<?xml version="1.0" encoding="UTF-8"?>
<bla xmlns="http://java.sun.com/xml/ns/javaee">
<display-name>test1</display-name>
<module>
<web>
<web-uri>RAV.war</web-uri>
<context-root>test2</context-root>
</web>
</module>
</bla>
And here's my XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="/bla/display-name">
<display-name>test2<display-name>
</xsl:template>
<xsl:template match="/bla/module/web/context-root">
<context-root>test3</context-root>
</xsl:template>
</xsl:stylesheet>
This should work but the result is that I am not seeing any transformation at all (it only applied identity transformation). It didn't match /bla/display-name or /bla/module/web/context-root.
When I removed the default namespace ("xmlns="http://java.sun.com/xml/ns/javaee") for <bla> tag, then the transformation worked as expected.
How come it could not match /bla/ if it contained this default namespace? How can I fix XSL so that it works? Thank you so much.