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

Re: parameter concatinating

Subject: Re: parameter concatinating
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 10 Aug 1999 16:39:35 +0200
xsl test parameter
At 99/08/07 14:51 -0400, Richard Lander wrote:
I am having trouble using parameters, using the July 09 draft. I'd like to use
parameters to pass patterns to named templates, then add to those patterns in
particular situations. For example, I've defined the path parameter for this
purpose. In the following XSLT fragment , I'm trying to add '/@id' to the
pattern in the path parameter.

<xsl:when test="$path/@id">

Variables can only be used in this way when they are of the type "node set", not when they are of any other type. Since you are talking about concatenation, I assumed you are working with string variables.


But it doesn't mean you are stuck.

        <xsl:call-template name="idcatcher_path">
          <xsl:with-param name="catch">url</xsl:with-param>
          <xsl:with-param name="path">child::SECTION[1]</xsl:with-param>
        </xsl:call-template>

Here you are assigning a *result tree fragment* to a variable, and the only things you can do with a result tree fragment is add the fragment structure (using copy-of) or the fragment value (using value-of) to the result tree.


Back to "concatenation", if you wanted to pass a string you would use:

<xsl:with-param name="path" select="'child::SECTION[1]'/>

... but this still won't help you.

But, if you get away from "concatenation" you will find what you are looking for if you use node sets as your variable type:

    <xsl:call-template name="idcatcher_path">
      <xsl:with-param name="catch">url</xsl:with-param>
      <xsl:with-param name="path" select="child::SECTION[1]"/>
    </xsl:call-template>

This will assign the node set relative to the current position to the variable named "path" and *then* you can do test="$path/@id".

An example is below, using your named template verbatim.

I hope this helps.

....... Ken


T:\FTEMP>type test.xml <?xml version="1.0"?> <MAIN> <SECTION id="instance-id"/> <SECTION/> </MAIN> T:\FTEMP>type test.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">

<xsl:template match="MAIN">
  <first>
    <xsl:call-template name="idcatcher_path">
      <xsl:with-param name="catch">url</xsl:with-param>
      <xsl:with-param name="path" select="child::SECTION[1]"/>
    </xsl:call-template>
  </first>
  <second>
    <xsl:call-template name="idcatcher_path">
      <xsl:with-param name="catch">url</xsl:with-param>
      <xsl:with-param name="path" select="child::SECTION[2]"/>
    </xsl:call-template>
  </second>
  <xsl:text>&#xa;</xsl:text>
</xsl:template>

<xsl:template name="idcatcher_path">
  <xsl:param name="catch"/>
  <xsl:param name="path"/>
  <xsl:choose>
    <xsl:when test="$path/@id">
      <xsl:attribute name="{$catch}"><xsl:value-of
                     select="$path/@id"/></xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
      <xsl:attribute name="{$catch}"><xsl:value-of
                     select="generate-id($path)"/></xsl:attribute>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>

T:\FTEMP>call xsl test.xml test.xsl testout.xml
T:\FTEMP>type testout.xml
<first url="instance-id"/><second url="N6"/>

T:\FTEMP>

--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-01-2
Next instructor-led training:   MS'99 1999-08-16  MT'99 1999-12-05/06


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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.