p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

xslt thread: Multiple parsing

Message #1 by Julio Merino <jmmv@h...> on Thu, 13 Jun 2002 22:15:12 +0200
The way you are doing it would work in XSLT 2.0 (with minor tweaks) but
it's not the XSLT 1.0 approach. XSLT 1.0 doesn't make it easy to create
and manipulate temporary trees (i.e. to create and process a piece of
XML within the stylesheet) - though you can do it, using the
xx:node-set() extension available in most processors.

Instead, in this case, call a named template with parameters:

<xsl:template name="make-link">
  <xsl:param name="href"/>
  <xsl:param name="text"/>
<a href="{$href}"><xsl:value-of select="$text"/></a>

<xsl:call-template name="make-link">
  <xsl:with-param name="href" select="'....'"/>
  <xsl:with-param name="text" select="'....'"/>

Michael Kay
Software AG
home: Michael.H.Kay@n...
work: Michael.Kay@s... 

> -----Original Message-----
> From: Julio Merino [mailto:jmmv@h...] 
> Sent: 13 June 2002 21:15
> To: P2P_XSLT
> Subject: [xslt] Multiple parsing
> Hello
> I've just started converting HispaBSD's webpage to XML+XSLT, 
> so I'm a complete beginner ;) So far, I've done the following 
> in index.xml:
> <webpage>
>   <title>Main</title>
>   <cvstag>$Id$</cvstag>
>   <content>
>     ( Here goes some XHTML stuff that is directly copied to 
> output currently ]
>   </content)
> </webpage>
> In the hispabsd.xsl file, I've defined the following to 
> process webpage element:
> <xsl:template match="/webpage">
>   <html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
>     <head>
>       (HEAD STUFF)
>     </head>
>     <body>
>          <a href="http://www.bsdi.com" target="blank">BSDi</a><br/>
>          <a href="http://www.darwin.org" 
> target="blank">Darwin</a><br/>
>       <xsl:apply-templates select="content"/>
>     </body>
> You have noticed all those weird links, right? Well, there is 
> the problem. I want to simplify them by using another tag, so 
> I've defined the following in the xslt:
> <xsl:template match="navlink">
>      <a href="{href}"><xsl:value-of select="text"/></a> 
> </xsl:template>
> And I want to replace all the above links to use this new 
> navlink tag. So I change them to: 
> <navlink><href>index.html</href><text>Principal</text></navlink>
> but here comes the problem. They do not get substituted... 
> because they are inside a template? I do not know the reason, 
> but I would like a solution to solve this... any idea?
> The question, summarized, is... can I make it to replace 
> 'navlink' elements that are INSIDE another template 
> (webpage)? If not, how would you solve this problem, that is, 
> without repeating the links menu in each xml page?
> If this is not possible, would I add the contents of the 
> links menu to a menu.xml file and then include it from the 
> xslt so it gets parsed? If so, how?
> Thanks a lot.
> -- 
> HispaBSD admin - http://www.hispabsd.org
> Julio Merino <jmmv@h...>

  Return to Index