XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Victoria LuSubject: Help for preceding-sibling in XSLT
Author: Victoria Lu
Date: 31 Oct 2006 11:51 AM
I have a xml data as A section below. I want to detect IC/@TYPE = '6f'|'ks' immediately preceding a <SB> but not <BF>. I wrote a .xsl as B section below. but result always show both '6f' and 'ks' before 'Sheraton.'.
How do I get rid of '6f' that is preceding a <BF> not <SB>?

(Attached a file "GOLD2008.dtd")

Thank you so much,
Victoria

---------A section-----------
<?xml version="1.0"?>
<!DOCTYPE CHAPTER SYSTEM "GOLD2008.dtd"
[

<!ENTITY del "">


<!ENTITY n "">
<!ENTITY ne "">
<!ENTITY slash "/">
]>
<CHAPTER><PARSE.ISBN TAG="1-4000-1682-7" /><INTRO><SEQ>40</SEQ>

<H TYPE="2">

<HEAD>Lucaya</HEAD>

<R PROPNUM="50798">

<IC TYPE="6f"/><IC TYPE="f2"/><BF>Our Lucaya Beach &amp; Golf Resort.</BF> Grand Bahama's grandest resort.[]

<IC TYPE="ks"/><SB>Sheraton.</SB> Geared toward family vacationers.[]

<SB>Westin Breakers Cay.</SB>.[]

<SB>Westin Lighthouse Pointe.</SB> Two-story structures.[]
</R>

</H>

</CHAPTER>

---------B section-----------

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:template match="/">
<html>
....
<body style="text-align: center">
<xsl:apply-templates select="CHAPTER/H/R"/>
</body>
</html>
</xsl:template>

<xsl:template match="CHAPTER/H/R">
<table width="100%" border="1">
<tbody>
<xsl:for-each select=".">
<xsl:if test="SB[preceding-sibling::*[1][self::IC]]|SB[preceding-sibling::*[1][self::BLT]]">
<tr style="background-color: bisque">
<td width="50%">
<xsl:for-each select="IC">
<xsl:choose>
<xsl:when test="IC[following-sibling::*[1][self::BF]]">
<li value="0">
<xsl:text> No IC/@TYPE before BF</xsl:text>
</li>
</xsl:when>
<xsl:when test="@TYPE eq'6f'">
<li value="0">
<xsl:value-of select="@TYPE"/>
</li>
</xsl:when>
<xsl:when test="@TYPE eq 'ks'">
<li value="0">
<xsl:value-of select="@TYPE"/>
</li>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</td>
<td width="50%">
<xsl:value-of select="SB[1]"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</tbody>
</table>
</xsl:template>

</xsl:stylesheet>


Documentgold2008.dtd
for xml file

Postnext
James DurningSubject: Help for preceding-sibling in XSLT
Author: James Durning
Date: 31 Oct 2006 03:03 PM
Change <xsl:when test="IC[following-sibling::*[1][self::BF]]">
to
<xsl:when test="following-sibling::BF and (following-sibling::*[name()='BF' or name()='SB'])[1]/name() = 'BF' ">
FILTER THIS NODE OUT
</xsl:when>

If this node has a following BF sibling, and the next BF or SB sibling it has is a BF one, then filter it out. This is only possible in XSLT 2.0, which you are using.

Postnext
Victoria LuSubject: Help for preceding-sibling in XSLT
Author: Victoria Lu
Date: 31 Oct 2006 03:15 PM
It's so cool! You saved my life!
Now, I'm wondering what to do if using XSLT 1.0

Postnext
James DurningSubject: Help for preceding-sibling in XSLT
Author: James Durning
Date: 01 Nov 2006 11:42 AM
In 1.0, due to the name() function, the syntax is a little different.
<xsl:when test="name((following-sibling::*[name()='BF' or name()='SB'])[1]) = 'BF'"/>

This actually works for both 1.0 and 2.0; was just unable to remember the exact syntax trick yesterday.

On further thought, you don't even need to initially test for following-sibling::BF, since if there are no following siblings, the test will simply return ('' =? 'BF') = false.

Posttop
Victoria LuSubject: Help for preceding-sibling in XSLT
Author: Victoria Lu
Date: 01 Nov 2006 11:50 AM
Can't believe you relyed to me again.
It's even cooler! Thank you expert!

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.