[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xpath for array of node names
Hi Jack, >Is it possible to construct an xpath which evaluates to an array of node names? Okay with your sample XML indented it's a little bit easier to understand :- <?xml version="1.0" encoding="utf-8"?> <propfind xmlns="DAV:"> <prop> <getcontentlength xmlns="DAV:"/> <getlastmodified xmlns="DAV:"/> <executable xmlns="http://apache.org/dav/props/"/> <resourcetype xmlns="DAV:"/> <checked-in xmlns="DAV:"/> <checked-out xmlns="DAV:"/> </prop> </propfind> As you know there are no array types in XPath 1.0 other than the node-set which feels a bit like an array. It's not exactly clear what you want to achieve in the end (i.e. to do with the "array" once you have it) so that might affect the answer. A simple transform like the following will give you the unprefixed names of the prop element children wrapped in an array-item element :- <xsl:template name="prop/*" mode="to-array"> <array-item> <xsl:value-of select="local-name(.)"/> </array-item> </xsl:template> Adding in a template rule for the prop element itself wraps the array-item elements in an array element := <xsl:template name="prop" mode="to-array"> <array> <xsl:apply-templates select="*" mode="to-array"/> </array> </xsl:template> You can then apply these templates inside an xsl:variable to the /propfind/prop element in to-array mode to do the translation. Unfortunately in XSLT 1.0 that will give you a result tree fragment and probably nothing useful to you. Refer 11.1 Result Tree Fragments in the spec http://www.w3.org/TR/xslt In short, there is no direct XPath 1.0 construct to do what I am trying to guess you want to know. Best suggestion is to reformulate your problem. Cheers Justin Johansson Justin Johansson Freelance XML / XSLT / XQuery Developer Australia procode(at)tpg(dot)com(dot)au
|
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
|