[xsl] How to parse a fragment result tree in the context of input tree

Subject: [xsl] How to parse a fragment result tree in the context of input tree
From: Janning Vygen <vygen@xxxxxxxxxxxx>
Date: Thu, 31 May 2001 17:20:24 +0200
Hi

first time i didnt get any answer, so i try again and explain my problem 
again with a short example:

the key problem is, that i can apply stylesheet to a fragment tree which is 
created in a template, but this fragment tree doesnt know where it belongs in 
the source tree. 

the second template generates a authorlist but can not include the proper 
class. How can you apply templates to a result tree fragment and still have 
access to the whole document??

i hope i  get some suggestion this time. but maybe i just cant properly 
explain my problem.

thanks in advance
janning

example.xsl:
<xsl:template match="authors">
  <xsl:variable name="authorlist">
     <itemizedlist>
       <xsl:for-each select="author">
         <listitem><xsl:value-of select="."/></listitem>
       </xsl:for-each>
     </itemizedlist>
  </xsl:variable>
  <xsl:apply-templates select="$authorlist"/>
</xsl:template>
<xsl:template match="itemizedlist">
  <ul>
    <xsl:attribute name="class">
      <xsl:value-of select="ancestor-or-self::chapter/@id"/>
    </xsl:attribute>
    <xsl:apply-templates/>
  </ul>
</xsl:template>


example.xml:
<book>
  <chapter id="first">
    <docinfo>
      <authors>
        <author>me</author>
        <author>myself</author>
        <author>and i</author>
      </authors>
    </docinfo>
    <itemizedlist>
      <listitem>normal</listitem>
      <listitem>list</listitem>
      <listitem>with items</listitem>
    <itemizedlist>
  </chapter>
  <chapter id="second">
    <itemizedlist>
      <listitem>another</listitem>
      <listitem>list</listitem>
      <listitem>with items</listitem>
    <itemizedlist> 
  </chapter>
</book>

html-result should be something like this:
<html>
<body>
<h1>chapter first</h1>
  written by 
  <ul class="first">
    <li>me</li> 
    <li>myself</li>
    <li>and i</li>
  </ul>
  <ul class="first">
    <li>normal</li>
    <li>list</li>
    <li>with items</li>
  </ul>
<h1>chapter second</h1>
  <ul class="first">
    <li>normal</li>
    <li>list</li>
    <li>with items</li>
  </ul>
</body>
</html>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread