Subject: Re: [xsl] xpath for array of node names From: Justin Johansson <procode@xxxxxxxxxx> Date: Thu, 19 Jul 2007 09:05:18 +0900 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] xpath for array of node n, Michael Kay | Thread | [xsl] [xslt 2.0] Local functions, Justin Johansson |
RE: [xsl] XSLT 2.0: Saxon et. al.: , Justin Johansson | Date | [xsl] [xslt 2.0] Local functions, Justin Johansson |
Month |