[xsl] Sablotron vs. Libxslt probelm

Subject: [xsl] Sablotron vs. Libxslt probelm
From: Andrew Borsz <andrew@xxxxxxxxxxxxxxx>
Date: Fri, 5 Aug 2005 18:48:14 -0400
Hello list,
I'm using XSLT 1.0 and I'm running into problems with a difference between Sablotron and Libxslt. I must use Libxslt for my project, but I'm having trouble getting the result I want. I've never had any problems with Libxslt before, but I've heard it's more 'strict'.


In the following example, Sablotron gives me the result I want. Libxslt gives me some duplicate output I don't want.

XML:

<root>
<component>
<unitMeta>
<unitTitle>unit title 1</unitTitle>
<unitSubtitle>unit sub title 1</unitSubtitle>
</unitMeta>
</component>
<component>
<unitMeta>
<unitTitle>unit title 2</unitTitle>
<unitSubtitle>unit sub title 2</unitSubtitle>
</unitMeta>
</component>
</root>

XSL:

<?xml version='1.0'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='xml' version='1.0'/>


<xsl:template match="root">
<document>
<xsl:apply-templates select="descendant::unitTitle[1]" mode="add"/>
<xsl:apply-templates select="descendant::unitSubtitle[1]" mode="add"/>
<xsl:apply-templates/>
</document>
</xsl:template>

<xsl:template match="component">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="unitMeta">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="unitSubtitle">
<subtitle><b><xsl:apply-templates/></b></subtitle>
</xsl:template>
<xsl:template match="root/component[1]//unitSubtitle[1]">
<!--do not process-->
</xsl:template>
<xsl:template match="root/component[1]//unitSubtitle[1]" mode="add">
<subtitle><b><xsl:apply-templates/></b></subtitle>
</xsl:template>

<xsl:template match="unitTitle">
<title><b><xsl:apply-templates/></b></title>
</xsl:template>
<xsl:template match="root/component[1]//unitTitle[1]">
<!--do not process-->
</xsl:template>
<xsl:template match="root/component[1]//unitTitle[1]" mode="add">
<title><b><xsl:apply-templates/></b></title>
</xsl:template>

</xsl:stylesheet>

There's extra output with Libxslt:

<title><b>unit title 1</b></title>
<subtitle><b>unit sub title 1</b></subtitle>

This appears twice. With Sablotron it appears only once, when called by the moded template. I have to use Libxslt. Please help.

Thanks,

Andrew Borsz

Current Thread