This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: determining whether an XPATH points to an element or attribute


>you can tell if you have an element or an attribute by
><xsl:if test="self::*">which is true just on element nodes
Thanks, this is exactly what I want.  All I have is a document with arbitrary XPATH's
i.e.

<path>//tagname1[fads and @fads]/tagname2</path>

I am using XSLT to process this file to create a second XSLT file.   The second XSLT
file has the template in it.

<xsl:template match="//tagname1[fads and @fads]/tagname2">
	<xsl:choose>
		<xsl:when test=" self::*"><!-- if it points to element -->
			<TagOperation>
		</xsl:when>
		<xsl:otherwise><!-- if it points to attribute-->
			<AttributeOperation>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

>but this is a rather strange thing to do as 999 times out of 1000 you
>always know in a template what kind of node is being matched.
Unless I can find out whether the XPATH points to an element or attribute before I create the
second XSLT I have to assume it could be either.

from Jeni post
>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.
I gather there is no simple way to do this with just an XPATH so I will need to test at runtime.

Thank a lot for your help

Edward

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]