This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: determining whether an XPATH points to an element or attribute
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Edward dot Middleton at nikonoa dot net
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 23 Jan 2002 10:33:36 +0000
- Subject: Re: [xsl] determining whether an XPATH points to an element or attribute
- Organization: Jeni Tennison Consulting Ltd
- References: <95B3DC792A040C45807C9CFA11B7B1AF02DE45C2@OHISV4.nikonoa.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Edward,
> I am generating a XSLT stylesheet from an XML file that looks like this.
>
> <path>//tagname</path>
> <path>//@attributename</path>
>
> some point to attributes and some pointing to elements.
And you want to generate different kinds of content for the templates,
depending on whether the path is for an element or attribute.
Really it depends on how complicated your patterns are. If you just
have ones in the form above, then you can test whether it matches an
element or attribute by seeing whether the first three characters are
'//@' or not:
<xsl:choose>
<xsl:when test="starts-with(., '//@')">
... attribute ...
</xsl:when>
<xsl:otherwise>
... element ...
</xsl:otherwise>
</xsl:choose>
If they're a little bit more complicated, then you might be able to
get away with just testing whether the patterns contain @ or not:
<xsl:choose>
<xsl:when test="contains(., '@')">
... attribute ...
</xsl:when>
<xsl:otherwise>
... element ...
</xsl:otherwise>
</xsl:choose>
But if they're really fairly complicated, with predicates and things,
then you need to write a XPath parser to work out whether they match
elements or attributes. And that's very difficult.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list