Reputation: 155
using question1 and question2 I am able to remove an Element's value based on attribute value using XSLT on non-namespaced XML But my input looks like this
<tns:message xmlns:tns="http://www.co.com/schemas/sys">
<Body xmlns="http://co.com/message">
<Record xmlns="http://schemas.co.com/Record/1.0">
<Book Class="NOVEL">Jungle Book</Book>
<Book Class="AUTOBIOGRAPHY">The Autobiography of Benjamin Franklin</Book>
</Record>
</Body>
</tns:message>
I have tried to use XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msg="http://co.com/message"
xmlns:rec="http://schemas.co.com/Record/1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="msg:Body/rec:Record/Book[@Class = 'NOVEL']/text()" />
</xsl:stylesheet>
But no luck.
When I have added namespace prefixes into input then it has worked.
Thank you in advance.
Upvotes: 0
Views: 175
Reputation: 117083
Default namespaces (without a prefix) are inherited. That means that the Book
elements in your input are in the same namespace as their parent Record
- and you need to change this:
<xsl:template match="msg:Body/rec:Record/Book[@Class = 'NOVEL']/text()" />
to:
<xsl:template match="msg:Body/rec:Record/rec:Book[@Class = 'NOVEL']/text()" />
Upvotes: 1