Subject: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 & Golf Resort.</BF> Grand Bahama's grandest resort.[]
<IC TYPE="ks"/><SB>Sheraton.</SB> Geared toward family vacationers.[]
Subject: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.
Subject: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.