Filtruj XML na podstawie wartości atrybutu za pomocą xslt
Szukałem tutaj i nie mogę znaleźć sposobu na filtrowanie xml na podstawie ich atrybutu. Mam ten plik XML:
<?xml version="1.0" encoding="utf-8"?>
<document>
<document_head>
<title>This is the title</title>
<version>This is the title</version>
</document_head>
<document_body>
<paragraph id="AXD">
<text>
This is a text that should be in the result
</text>
<properties>
<size>13px</size>
<color>#000000</color>
</properties>
<author>Current user</author>
</paragraph>
<paragraph id="SFI">
<properties>
<text>
This is some other text that should not be in there
</text>
</properties>
</paragraph>
<paragraph id="SFA">
<author>Some random guy</author>
</paragraph>
<paragraph id="ARG">
This doesn't mean anything.
</paragraph>
<paragraph id="RRR">
This does, hence should be in there.
</paragraph>
</document_body>
</document>
Oczekuję tego wyniku:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<document_head>
<title>This is the title</title>
<version>This is the title</version>
</document_head>
<document_body>
<paragraph id="AXD">
<text>
This is a text that should be in the result
</text>
<properties>
<size>13px</size>
<color>#000000</color>
</properties>
<author>Current user</author>
</paragraph>
<paragraph id="RRR">
This does, hence should be in there.
</paragraph>
</document_body>
</document>
Obecnie mam ten XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="document_body/paragraph[not(@id='AXD')][not(@id='RRR')]" />
</xsl:stylesheet>
Który wytwarza ten XML:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<document_head>
<title>This is the title</title>
<version>This is the title</version>
</document_head>
<document_body>
<paragraph id="AXD">
<text>
This is a text that should be in the result
</text>
<properties>
<size>13px</size>
<color>#000000</color>
</properties>
<author>Current user</author>
</paragraph>
</document_body>
</document>
Czy wiesz, czego brakuje?
Dzięki.
Aktualizacja: Wygląda na to, że kod działa na innym procesorze XSLT, ale nie działa na Java Transformer.