xsl-list
[Top] [All Lists]

Re: parameter use in XPath

2003-10-22 16:40:59
The variable being passed by the command line is the same thing as far as
the XSLT processor in concerned.  There are some work arounds to this issue
that you may find useful.  Heres one...

<xsl:param name="keyword"/>
<xsl:key name="keywordMatch" match="foo" use="@bar"/>

<xsl:template match="/">
<xsl:for-each select="//foo/bar">
    <xsl:for-each select="key(keywordMatch, $keyword)">
        ...
    </xsl:for-each>
</xsl:for-each>
</xsl:template>

Best of luck...

M.

----- Original Message ----- 
From: "Saverio Perugini" <sperugin(_at_)csgrad(_dot_)cs(_dot_)vt(_dot_)edu>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Wednesday, October 22, 2003 4:43 PM
Subject: [xsl] parameter use in XPath


Hello,

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,
Saverio

--

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

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

<!-- 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()[(_at_)refid]">
10:    <xsl:for-each select="descendant::node()[(_at_)refid]">
11:        <xsl:variable name="target-id" select="@refid"/>
12:         <xsl:variable name="target-node"
select="//node()[(_at_)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>
23:</xsl:template>

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

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



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



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