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

Re: passing and retrieving parameter to a template

Subject: Re: passing and retrieving parameter to a template
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Tue, 16 Apr 2002 13:56:46 -0400
xs schema xs element
As best as I can see, you have two templates matching the same path.  You
think  you will get the second one when you use <xsl:apply-templates>, but
you will not.  From the context in which the second template is called,
there will be no elements matching

"/xs:schema/xs:element/xs:complexType/xs:sequence
/xs:element/xs:complexType/xs:sequence/xs:element"

So either the second template will not get called at all (the first one has
priority), or, if it ever did get called, it would not be from the first one
and so the parameter would not have been assigned.

You should decide what path you really want to match with the second
template.

Also, it would be very unusual to need to have a template with such a
detailed path as you are using.  The template will process all xs:element
that are within xs:sequences that are within the various other elements.
It's very specific.  Aren't you really traversing the entire schema pulling
out the interesting parts?  A more typical approach would be like this:

<xsl:template match='xs:schema'>
    <!-- Process elements-->
    <xsl:apply-templates select='xs:element' mode='top-level'/>
    <!-- Process complex types-->
    <xsl:apply-templates select='xs:complexType' mode='top-level'/>
</xsl:template>

<xsl:template match='xs:element' mode='top-level>
    <!-- Process element declarations here -->
    <!-- Get all inline complex types first-->
    <xsl:apply-templates select='xs:complexType' mode='inline'/>
</xsl:template>

<xsl:template match='xs:complexType' mode='top-level'>
    <!-- Process named complex type declarations  here -->
</xsl:template>

<xsl:template match='xs:complexType' mode='inline>
    <!-- Process inline complex type declarations  here -->
</xsl:template>

<!-- And so on ...-->

Cheers,

Tom P

[Najmi, Jamal]

> I have a variable defined in one template.  This variable actually
contains
> the value of an attribute.  I am passing the value of this variable as a
> parameter to another template.  But when I retrieve the value of the
> variable it is empty.
>
> I have been banging my head for a while on this.  Please help!!
>
>
> Following is the code snippet:
>
> <xsl:template
> match="/xs:schema/xs:element/xs:complexType/xs:sequence/xs:element">
>         <xsl:variable name="sectionShortName"><xsl:value-of
> select="./@name"></xsl:value-of></xsl:variable>  //assigning value
>      <h1><xsl:value-of
>
select="/xs:schema/xs:annotation/xs:appinfo/dne:template/dne:constrainedElem
> ent[@name=$sectionShortName]/dne:constraint/@label"/></h1>
>      <blockquote>
>     <blockquote>
>      <blockquote>
>      <p>&#160;</p>
>      <table width="64%" border="0" align="center">
>       <xsl:value-of select = "$sectionShortName" />
>       <xsl:apply-templates>
>            <xsl:with-param name = "sectionShortNameParam"
> select="$sectionShortName"/>    // passing value
>        </xsl:apply-templates>
>       </table>
>         <p>&#160;</p>
>       </blockquote>
>     </blockquote>
>   </blockquote>
> </xsl:template>
> <xsl:template
>
match="/xs:schema/xs:element/xs:complexType/xs:sequence/xs:element/xs:comple
> xType/xs:sequence/xs:element">
>        <xsl:param name = "sectionShortNameParam" />            //
declaring
> local parameter
>        <xsl:value-of select = "$sectionShortNameParam" />   // retrieving
> value
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 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.