xsl-list
[Top] [All Lists]

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

2007-06-07 13:54:56
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(_dot_)Williams(_at_)the401kcompany(_dot_)com> 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(_at_)gmail(_dot_)com]
Sent: Thursday, June 07, 2007 1:41 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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(_at_)nag(_dot_)co(_dot_)uk> 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.
> ______________________________________________________________________
> __
>
> --~------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
> --~--
>
>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--