[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|