Reputation: 66560
I want to convert xml file using xsltproc and only extract some portions of it, I have xslt like this:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="xml"
indent="yes"
encoding="iso-8859-1" />
<xsl:template match="glossary">
<ul>
<xsl:for-each select="*/glossentry">
<li>
<h2><xsl:value-of select="glossterm"/> (<xsl:value-of select="abbrev/emphasis"/>)</h2>
<div><xsl:value-of select="*/para"/></div>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
But it show all other text that was inside xml as text. What's need to be added or change to only show something like this?
<html><body>
<ul>
<li>
<h2>Term (abbrev)</h2>
<div>Para</div>
</li>
<li>
<h2>Term2 (abbrev2)</h2>
<div>Para2</div>
</li>
...
</ul>
Upvotes: 0
Views: 1112
Reputation: 66560
Ok, I found it, I need to add select to apply-templates
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="xml"
indent="yes"
encoding="iso-8859-1" />
<xsl:template match="part">
<xsl:if test="@id = 'lexicon'">
<xsl:apply-templates select="glossary"/>
</xsl:if>
</xsl:template>
<xsl:template match="glossary">
<ul>
<xsl:for-each select="*/glossentry">
<li>
<h2><xsl:value-of select="glossterm"/>
<xsl:if test="abbrev">
<xsl:text>: </xsl:text>
<xsl:for-each select="abbrev/*">
<xsl:if test="position() > 1">, </xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:if>
</h2>
<div><xsl:value-of select="*/para"/></div>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="book">
<html>
<title><xsl:value-of select="title"/></title>
<body>
<xsl:apply-templates select="part"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1