[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Problem with grouping the handling of sibling nodes

Subject: Problem with grouping the handling of sibling nodes
From: Olaf Meske <omeske@xxxxxxxxxxx>
Date: Tue, 08 Mar 2005 14:24:42 +0100
xsl when test eq
Hi,

I try to convert some special tags into some more regular tags.
I have something like <starttag/>sometext<endtag/>, but starttag and endtag are tags without content, the content is the sometext.


So I have an example xml and a suggestion for an xsl, but it does not work.

The example xsl runs mostly within XMLSpy but I have to use Saxon8 in my application, and that gave me an exception.
I try to stripp the xsl until it runs with saxon, but than I lost almost of my functionality.


So If someone could give me an advice how to do this with saxon or what else to do.
I I would be very grateful if someone could help me.


Regards
Olaf

Here are the XML (tinytest.xml)
=======================================================================
=======================================================================
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="tinytest.xsl"?>
<document>
<story>Test text with
<tabcontent>
<row>
<cell>cell 1</cell>
<cell>cell 2<start type="1"/>TEST TAG TEXT<end endfor="start"/></cell>
<cell>cell 3<start type="5"/>TEST TAG TEXT<end endfor="start"/> </cell>
</row>
</tabcontent> more <start type="2"/>TEST TAG TEXT<end endfor="start"/>
if TEST <start type="3"/><test desc="should be removed"/>TEST TAG
<test1 desc="should be removed">also trash</test1><end endfor="start"/>would need.
And another test text TEST TAG TEXT with some regex markup.
<start type="4"/>TEST TAG TEXT<end endfor="start"/></story>
</document>
=======================================================================
=======================================================================
and the XSL (tinytest.xsl)
=======================================================================
=======================================================================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com/tinytest"
>


<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

	<xsl:template match="/">
	<xsl:apply-templates />
	</xsl:template>

	<xsl:template match="story" >
		<text x="single story">
			<xsl:for-each select="node()">
				<xsl:call-template name="breaktest"/>
			</xsl:for-each>
		</text>
	</xsl:template>
	
	<xsl:template match="cell" >
		<td x="single cell">
			<xsl:for-each select="node()">
				<xsl:call-template name="breaktest"/>
			</xsl:for-each>
		</td>
	</xsl:template>

	<xsl:template match="row" >
		<tr>
			<xsl:apply-templates />
		</tr>
	</xsl:template>

	<xsl:template match="tabcontent" >
		<table>
			<xsl:apply-templates />
		</table>
	</xsl:template>

<xsl:template name="breaktest">
<xsl:choose>
<xsl:when test="(name() eq 'start')
and (following-sibling::*[1]/name() eq 'end')
and (following-sibling::*[1]/@endfor eq 'start') ">
<FoundStart>
<xsl:attribute name="mytype"><xsl:value-of select="@type"/></xsl:attribute>
</FoundStart>
</xsl:when>
<xsl:when test="(name() eq 'end')
and (@endfor eq 'start')
and (preceding-sibling::*[1]/name() eq 'start')"><FoundEndWillBeDeleted/></xsl:when>
<xsl:when test="(self::text())
and (preceding-sibling::*[1]/name() eq 'start')
and (following-sibling::*[1]/name() eq 'end')
and (following-sibling::*[1]/@endfor eq 'start')"><FoundTextWillBeDeleted/></xsl:when>
<xsl:when test="(self::text())">
<xsl:analyze-string select="." regex="(.*?)(TEST TAG TEXT)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/><FoundTextWillBeChanged/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:when>
<xsl:otherwise>
<xsl:analyze-string select="." regex="(.*?)(TEST TAG TEXT)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/><FoundTextWillBeChanged/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>

=======================================================================
=======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.