xsl-list
[Top] [All Lists]

Re: [xsl] xpath for array of node names

2007-07-18 16:36:03
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>