Re: XPath help

Subject: Re: XPath help
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Sun, 12 Nov 2000 12:56:34 +0000

Mathias Bonnard wrote:
> 
> 
> There might be a simpler version (especially avoiding the double test on
> preceding and following)...
> 
for a sample file:
---
<root>
	<x name="a">x:a</x>
	<x name="b">x:b1</x>
	<x name="b">x:b2</x>
	<x name="c">x:c</x>
</root>
---

you can use test="count(//*[@name = ./@name]) = 1" :

---
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0" >
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<xsl:copy>
			<xsl:apply-templates select="root"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="x">
		<xsl:if test="count(//*[@name = ./@name]) = 1">
			<xsl:copy-of select="."/>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>
---

It's probably not very efficient - you'd need a Muenchian solution (I
suspect) for large documents.

Francis.
-- 
Francis Norton.

why not?


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread