xsl-list
[Top] [All Lists]

RE: Unique local-name()

2003-02-22 22:10:12
Hi Niklas:

I don't think you'll find any context free, Xpath only method of doing
this.  Reason why is because the current() function always takes you out
to the current node.

For an XSLT solution, here's what I recommend:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
        <xsl:key match="/root/*" use="local-name()" name="local-name"/>
        
        <xsl:template match="root">
                <xsl:copy-of
select="*[not(key('local-name',local-name())[2])]"/>
        </xsl:template>
</xsl:stylesheet>

This is simply does a key on the local name of all children of root, and
copies a node if there is no second node with the same name.  If you
want to do any more processing on the node, simply apply-templates
instead of copy-of.

HTH!

Dion

-----Original Message-----
From: Niklas Gustavsson [mailto:niklas(_at_)protocol7(_dot_)com] 
Sent: Saturday, February 22, 2003 6:29 PM
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com

Hi all,

I'm really stuck on a XPpath problem that should be fairly simple (I
think): I need to check if an element that got a unique local-name()
among it's siblings. And, I have no way of actually knowing the
local-name() when I generate the XPath.

For example:
<root>
        <a />
        <b />
        <b />
        <c />
        <c />
        <d />
</root>

a and d should pass, the b's and c's shouldn't

If my question isn't clear enough I try to clarify my problem some more
:-)

Thanks!
/niklas



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




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



<Prev in Thread] Current Thread [Next in Thread>