[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Using one nodeset to dictate the format of data from another nodeset


Subject: RE: [xsl] Using one nodeset to dictate the format of data from another nodeset
From: "Angela Williams" <Angela.Williams@xxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Jun 2007 16:03:43 -0500

Your understanding is correct.

If you eliminated the param from the content template, the title
template would still pick up the level that was "tunneled" from the
topic-ref template.  It is a way of declaring a parameter in one place
and using it downstream without having to pass it through template by
template.  Where the parameter originates, it is declared as a tunnel
parameter (with-param, tunnel="yes").

The templates that need to use it 'register' as a 'tunnel opening'
parameter by specifying tunnel="yes" on the xsl:param declaration.


Thanks!
Angela

-----Original Message-----
From: Rebecca O'Connell [mailto:rebecca321@xxxxxxxxx]
Sent: Thursday, June 07, 2007 3:55 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Using one nodeset to dictate the format of data from
another nodeset

It works perfectly. I notice it behaves the same way if I take out all
of the "tunneling" parameters. What is "tunneling" supposed to do? (I
thought it might make it so I could just declare my parameter in
topic-ref and then use it in title without all the redundant xsl:param
and xsl:with-param calls, but apparently not.)

Thanks,
Rebecca

On 6/7/07, Angela Williams <Angela.Williams@xxxxxxxxxxxxxxxxxx> wrote:
> You are calling your title and content templates and passing
> parameters using with-param correctly (assuming you don't want to
> tunnel), but the title and content templates don't have an 'accepting'

> parameter definition, so the parameters are being discarded.  The
> following seems to get the output you want.
>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>   <xsl:strip-space elements="*"/>
>
>   <xsl:template match="/">
>     <html>
>       <head>
>       </head>
>       <body>
>         <xsl:apply-templates select="x/structure-data"/>
>       </body>
>     </html>
>   </xsl:template>
>
>
>   <xsl:template match="topic-ref">
>     <xsl:param name="level"  tunnel="yes"
> select="count(ancestor::topic-ref)+1"/>
>     <div class="TOPIC-REF">
>       <xsl:apply-templates select="key('id', @idref)">
>         <xsl:with-param name="level" tunnel="yes" select="$level"/>
>       </xsl:apply-templates>
>
>       <xsl:apply-templates select="topic-ref"/>
>     </div>
>   </xsl:template>
>
>   <xsl:template match="content">
>     <xsl:param name="level" tunnel="yes"/>
>
>     <xsl:apply-templates select="title" >
>       <xsl:with-param name="level" tunnel="yes" select="$level"/>
>     </xsl:apply-templates>
>   </xsl:template>
>
>   <xsl:template match="title">
>     <xsl:param name="level" tunnel="yes"/>
>
>     <xsl:element name="{concat('h',$level)}">
>       <xsl:value-of select="." />
>     </xsl:element>
>   </xsl:template>
>
>   <xsl:key name="id" match="content" use="@id"/> </xsl:stylesheet>
>
>
>
>
>
> Thanks!
> Angela
>
> -----Original Message-----
> From: Rebecca O'Connell [mailto:rebecca321@xxxxxxxxx]
> Sent: Thursday, June 07, 2007 1:41 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Using one nodeset to dictate the format of data
from
> another nodeset
>
> David assumed correctly that I had one document with two parts. Your
> solution worked beautifully. I had a feeling that there was some
simple
> way I was missing. I am a much happier camper (see below for the
reason
> why I am not yet a completely happy camper).
>
> I don't mind being corrected. I would much rather be told I'm using a
> term incorrectly than continue using it incorrectly.
>
> With regard to the second part of my question (how to "feed" a
template
> data from the template that called it), I am new to parameters (and to
> XSLT) and am having some difficulty figuring out how to handle them.
> Here's what I think I know about parameters:
>
> 1. xsl:param - used with stylesheets and templates, sets the parameter
> 2. xsl:with-param - used with apply-templates and call-template,
changes
> the default value of the parameter, passes the parameter to the
template
> being called (?) 3. xsl:value-of or select/name="{$paramName}" - used
to
> get the value of the parameter 4. Tunnel parameters "have the property
> that they are automatically passed on by the called template to and
> further templated that it calls, and so on recursively" (as described
by
> Oxygen).
>
> However, clearly I don't know enough, because my attempts to use
> parameters are not working. Below is what I attempted:
>
> XML:
> <x>
> <source-data>
>     <content id="id1"><title>Title 1</title></content>
>   <content id="id2"><title>Title 2</title></content> </source-data>
>
> <structure-data>
>   <topic-ref idref="id1" >
>      <topic-ref idref="id2" />
>   </topic-ref>
> </structure-data>
> </x>
>
>
>
> DESIRED OUTPUT:
> <html>
>   <div><h1>Title 1</h1>
>     <div><h2>Title 2</h2></div>
>  </div>
> </html>
>
> STYLESHEET ATTEMPT:
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>
> <xsl:strip-space elements="*"/>
>
>   <xsl:template match="/">
>     <html>
>       <head>
>       </head>
>       <body>
>         <xsl:apply-templates select="x/structure-data"/>
>       </body>
>     </html>
>   </xsl:template>
>
>
>   <xsl:template match="topic-ref">
>     <xsl:param name="level"  tunnel="yes"
select="count(ancestor::*)"/>
>     <div class="TOPIC-REF">
>           <xsl:apply-templates select="key('id', @idref)">
>             <xsl:with-param name="level" tunnel="yes"
> select="count(ancestor::*)"/>
>           </xsl:apply-templates>
>            <xsl:apply-templates select="topic-ref"/>
>         </div>
>    </xsl:template>
>
> <xsl:template match="content">
>         <xsl:apply-templates select="title" >
>             <xsl:with-param name="level"/>
>           </xsl:apply-templates>
> </xsl:template>
>
>   <xsl:template match="title">
>       <xsl:element name="{concat('h',$level)}">
>           <xsl:value-of select="." />
>       </xsl:element>
>  </xsl:template>
>
>   <xsl:key name="id" match="content" use="@id"/> </xsl:stylesheet>
>
> What am I getting wrong here?
>
> Thank you,
> Rebecca
>
> On 6/7/07, David Carlisle <davidc@xxxxxxxxx> wrote:
> >
> >
> > > (David Carlisle is also making it more difficult, by giving you a
> > > lecture about what node-sets are. He's right of course, but you're
> > > not the only one to misuse the term).
> >
> > yes, main reason I added that bit (in addition to the actual answer)
> > was that I couldn't tell what was meant by "2 node sets" as there
was
> > the possibility that it meant two documents (since the input was
shown
>
> > as two xml fragments). Misusing technical terms isn't  a sin and as
> > you say it's not uncommon, but sometimes it actually stops the
> > question being understood.
> >
> > David
> >
> >
> >
______________________________________________________________________
> > __ The Numerical Algorithms Group Ltd is a company registered in
> > England and Wales with company number 1249803. The registered office
> > is:
> > Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
> >
> > This e-mail has been scanned for all viruses by Star. The service is
> > powered by MessageLabs.
> >
______________________________________________________________________
> > __


Current Thread
Keywords
xml