I'm having hard times in triggering an xsl action only on distinct values. Here's an excerpt of my XML file:
<?xml version="1.0" encoding="UTF-8" ?>
<Doc Data="February 2010">
<Title>Title 1</Title>
<Subject>Subject 1</Subject>
</Doc>
<Doc Data="January 2010">
<Title>Title 2</Title>
<Subject>Subject 2</Subject>
</Doc>
<Doc Data="January 2010">
<Title>Title 3</Title>
<Subject>Subject 3</Subject>
</Doc>
And this is my xsl file:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:objUtility="urn:utility"
version="1.0">
<xsl:output method="html" indent=开发者_运维百科"no" encoding="ISO-8859-1"/>
<xsl:template match="Doc">
<xsl:if test="not(@Data = preceding-sibling::Doc/@Data)">
<xsl:value-of select="@Data" />
</xsl:if>
</xsl:template>
<xsl:apply-templates />
The problem is that, with this code, the preceding-sibling::Doc/@Data element always contains ONLY THE FIRST element, so basically I get a distinct value only for February and not for January. Where am I wrong? I must use XSL 1.0
If you wish to ask “Is there any preceding sibling of type Doc with a Data attribute equal to the Data attribute of the current node?”, the XPath for that should look like
<xsl:if test="not(preceding-sibling::Doc[@Data = current()/@Data])">
精彩评论