xsl-list
[Top] [All Lists]

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

2007-06-07 11:41:10
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>
--~--