I am currently attempting to Wrap nodes within a center para into one center
tag by checking the length of the preceding sibling. If the length of the
preceding sibling is greater than Zero, then a center tag has already been
opened so nothing needs to be done. Otherwise open a center tag. I have
included a test xml structure and a portion of the xslt that attempts to
handle this. I am using the same reverse logic to close the <Center> tag.
i.e string-length(parent::*/following-sibling::*)>0
The problem I seem to be having with this is that text() for instance the
text "Chapter on Testing:" can not be considered a preceding-sibling of
<AddText>Testing FAQ</AddText> even though they have the same <Center>
parent tag since preceding-sibling does not grab the text node.
Is there a better way of checking the length of the closest preceding text
node that is a 'sibling' of the context node?
I attempted using
string-length(parent::*/preceding::*[1])>0
but this does not ensure that I am pulling a node that is a child of the
same parent node. When I try using the reverse i.e
string-length(parent::*/following::*[1])>0 to close the center tag, the tag
closes right after the first text(), in this case after the sentence
"Chapter on Testing:"
Thanks, I will very much appreciate any suggestions.
Besi
***********************************************
<Book>
<TitleHead>
<TitleNum>
Chapter 1.
</TitleNum>
<Center>
Chapter on Testing:
<AddText>Testing FAQ</AddText>
<StrikeText>Questions</StrikeText>
</Center>
</TitleHead>
</Book>
***********************************************
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<!--Wrap Center child tags by check if the length of preceding sibling of
Text parent nodes such as AddText and Strike Text within the Center tags is
zero-->
<xsl:template match="text()">
<xsl:if test="ancestor::Center">
<xsl:choose>
<xsl:when test ="name(../..)='Center' and
string-length(parent::*/preceding-sibling::*)>0">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text
disable-output-escaping='yes'><center></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
--~------------------------------------------------------------------
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>
--~--