xsl, copy only one, but have all content?
I have
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
<article lang="en">
<articleinfo>
<title>Test Article</title>
</articleinfo>
<sect1 label="">
<title>Test1 Section</title>
<para>Some content</para>
</sect1>
<sect1>
<title>Test2 Section</title>
<para>Another content</para>
</sect1>
</article>
I want extract only one sect1 with title "Test1", so I write such simple
xsl transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://docbook.org/ns/docbook">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="article/sect1[contains(title, 'Test1')]">
<xsl:message>Match</xsl:message>
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
But for some unknown reason such transformation not copy only sect1 with
mentioned title, but also content of all XML file minus tags:
xsltproc ./extract_sect1.xsl test.xml
Match
<?xml version="1.0"?>
Test Article
<sect1 label="">
<title>Test1 Section</title>
<para>Some content</para>
</sect1>
Test2 Section
Another content
So question, why I get "Test2 Section" and "Another content", and how can
I fix this situation?
No comments:
Post a Comment