[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

parameter use in XPath

Subject: parameter use in XPath
From: Saverio Perugini <sperugin@xxxxxxxxxxxxxxxx>
Date: Wed, 22 Oct 2003 18:43:45 -0400 (EDT)
xsl parameter

Is it possible to use the parameter "keyword" (line 1) in
XPath expressions (lines 5, 13, and 27) in the following stylesheet
without the use of specific processor extensions?

I know one may not use variables set by the stylesheet in
XPath expressions, but $keyword is passed from the command line
and thus not computed or set by the stylesheet.

Many thanks in advance,


 1:<xsl:param name="keyword"/>

 2:<xsl:template match="{$keyword}">
 3:   <xsl:apply-templates/>

<!-- matches all nodes which have a descendant-or-self,
     which is an ancestor-or-self::d and a leaf,
     and does nothing with them -->
 5:<xsl:template match="node()[not (descendant-or-self::node()[ancestor-or-self::{$keyword} and count (child::node()) = 0])]">

 6:  <xsl:variable name="original-node" select="."/>
 7:  <xsl:variable name="original-node-name" select="name()"/>
 8:  <xsl:variable name="original-node-id" select="@id"/>

   <!-- match a node who has a descendant with a refid attribute, e.g., e -->
 9:  <xsl:if test="descendant::node()[@refid]">
10:    <xsl:for-each select="descendant::node()[@refid]">
11:        <xsl:variable name="target-id" select="@refid"/>
12:         <xsl:variable name="target-node" select="//node()[@id=$target-id]"/>
13:         <xsl:if test="$target-node[descendant-or-self::node()[ancestor-or-self::{$keyword} and count (child::node()) = 0]]">

14:            <xsl:element name="{$original-node-name}">
15:               <xsl:attribute name="id">
16:                  <xsl:value-of select="$original-node-id"/>
17:               </xsl:attribute>
18:               <xsl:apply-templates select="$original-node/*"/>
19:            </xsl:element>
20:         </xsl:if>
21:      </xsl:for-each>
22:   </xsl:if>

<!-- matches all crosslinks and -->
24:<xsl:template match="node()[@refid]" priority="0.7">
25:   <xsl:variable name="target-id" select="@refid"/>
26:   <xsl:variable name="target-node" select="//node()[@id=$target-id]"/>

   <!-- only copies those which have a descendant-or-self,
        which has a reference to a node,
        which is an ancestor-or-self::d and a leaf -->
27:   <xsl:if test="$target-node[descendant-or-self::node()[ancestor-or-self::{$keyword} and count (child::node()) = 0]]">
28:      <xsl:copy>
29:         <xsl:attribute name="refid">
30:            <xsl:value-of select="$target-id"/>
31:         </xsl:attribute>
32:      </xsl:copy>
33:   </xsl:if>

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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.