xsl-list
[Top] [All Lists]

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

2007-10-25 20:41:26
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



--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] [XSL]Selecting Sibling from the Top of the Tree, Alice Ju-Hsuan Wei <=