[xsl] [XSL]Selecting Sibling from the Top of the Tree

Subject: [xsl] [XSL]Selecting Sibling from the Top of the Tree
From: Alice Ju-Hsuan Wei <ajwei@xxxxxxxxxxx>
Date: Thu, 25 Oct 2007 23:40:55 -0400
Hi,

The XML I have below, I have been successfully using the id function to generate the output to print out "Technology" as the topic of the book. However, I would also like to print out the other one, "Resources" with the display of the result. Since I marked the id only as tech, how can I actually get it to print out the preceding or following sibling, without having to mark all the associated ids that go along with it?


XSLT:


   <xsl:template match="book">
               <div>
           <p>
               <span class="booklist">
        Topic:
                   <xsl:call-template name="print"/>
               </span>
           <xsl:apply-templates/>
</xsl:template>

<xsl:template name="print">

               <xsl:choose>
           <xsl:when test="count(ancestor::subject) &gt; 1 ">
               <xsl:if test="preceding-sibling::subject !=''">
                   [Also Used for:
           <xsl:value-of select="."/>]
               </xsl:if>
               <xsl:if test="following-sibling::subject !=''">
                   [Also Used for: <xsl:value-of select="."/>]
                </xsl:if>
               <xsl:value-of select="id(@topic)"/>
           </xsl:when>
           <xsl:otherwise>
               <xsl:apply-templates select="id(@topic)"/>
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>


XML:


[---------- The portion is in the header section 6 levels away from the <book>
<topicList>
<subject xml:id="tech">Technology</subject>
<subject xml:id="res">Resource</subject>
<subject xml:id="progr">Programming Language</subject>
</topicList>
--------------]

<body>
<book topic="tech" rendition="xslt" author="Tennison, Jeni" title="Beginning XSLT">


<p>New York: Apress, 2002.</p>
<p>The book serves as an introduction to XSLT based on the examples of a television program set. A resourceful book for those new to the technology.</p>
</book>
</body>


Desired Output:

<div><p><span class="booklist">Topic: Technology Resource Programming Language</span>
<p>Tenison, Jeni.</span> Beginning XSLT. New York: Apress, 2002. </p>
<p>The book serves as an introduction to XSLT based on the examples of a television program set. A resourceful book for those new to the technology.</p>


Thanks to those who can help out.

Alice

Current Thread