[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: determining whether an XPATH points to an element

Subject: Re: determining whether an XPATH points to an element or attribute
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 23 Jan 2002 10:33:36 +0000
xpath complicated predicates
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.