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

Problem setting ENDTAG in new XML Document

Subject: Problem setting ENDTAG in new XML Document
From: nikken@xxxxxxxxxx
Date: Fri, 28 Nov 2003 10:19:01 +0100
aaa aab aac
I want to convert an existing XML Document to an other XML Document using
XSLT. The new Document
sould include new Group-Main-Tags with the following rule:
AAA -> Group1 (AAB and AAC) repeat:0..n 
BBB -> Group2 (subtag of Group1, with BBA,BBC) repeat:0..n

The Source-Document looks like this:
====================================
<MAIN>
	<MSG>1.0</MSG>
	<ORG>2.0</ORG>
	<AAA>3.0.0</AAA>
	<AAB>3.0.1</AAB>
	<AAC>3.0.2</AAC>
	<BBB>4.0.0</BBB>
	<BBA>4.0.1</BBA>
	<BBB>4.1.0</BBB>
	<BBA>4.1.1</BBA>
	<AAA>3.1.0</AAA>
	<AAB>3.1.1</AAB>
	<AAA>3.2.0</AAA>
	<BBB>4.1.0</BBB>
	<BBA>4.1.1</BBA>
	<BBC>4.1.2</BBC>
</MAIN>

The new Document sould look like this:
======================================

<?xml version="1.0" encoding="UTF-8"?>
<MAIN>
	<MSG>1.0</MSG>
	<ORG>2.0</ORG>
	<Group1>
		<AAA>3.0.0</AAA>
		<AAB>3.0.1</AAB>
		<AAC>3.0.2</AAC>
		<Group2>
			<BBB>4.0.0</BBB>
			<BBA>4.0.1</BBA>
		</Group2>
		<Group2>
			<BBB>4.1.0</BBB>
			<BBA>4.1.1</BBA>
		</Group2>
	</Group1>
	<Group1>
		<AAA>3.1.0</AAA>
		<AAB>3.1.1</AAB>
	</Group1>
	<Group1>
		<AAA>3.2.0</AAA>
		<Group2>
			<BBB>4.1.0</BBB>
			<BBA>4.1.1</BBA>
			<BBC>4.1.2</BBC>
		</Group2>
	</Group1>
</MAIN>

My problem was to set the ENDTAGS. I tried to do it using XPath .... Here
the not working Stylesheet
witch generate a non well formed XML Dokument.

<!--*************************** THIS STYLESEET IS NOT WORKING CORRECT ******************
-->
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template match="/">
		<MAIN>
			<xsl:for-each select="MAIN/*">
				<xsl:if test="name() = 'AAA'">
					<xsl:call-template name="setEndTagBBBGroup2"/>
					<xsl:call-template name="setEndTagAAAGroup1"/>
					<xsl:call-template name="setBeginTagAAAGroup1"/>
				</xsl:if>
				<xsl:if test="name() = 'BBB'">
					<xsl:call-template name="setEndTagBBBGroup2"/>
					<xsl:call-template name="setBeginTagBBBGroup2"/>
				</xsl:if>
				<xsl:variable name="tag">
					<xsl:value-of select="name()"/>
				</xsl:variable>
				<xsl:element name="{$tag}">
					<xsl:value-of select="."/>
				</xsl:element>
			</xsl:for-each>
			<xsl:call-template name="setEndTagBBBGroup2"/>
			<xsl:call-template name="setEndTagAAAGroup1"/>
		</MAIN>
	</xsl:template>
	
	<xsl:template name="setEndTagAAAGroup1">
		<!-- get prev node in node-set -->
		<xsl:if test="preceding::AAA[1]">
			<xsl:text disable-output-escaping="yes">&lt;/Group1&gt;</xsl:text>
		</xsl:if>
	</xsl:template>
	<xsl:template name="setBeginTagAAAGroup1">
		<xsl:text disable-output-escaping="yes">&lt;Group1&gt;</xsl:text>
	</xsl:template>
	<xsl:template name="setEndTagBBBGroup2">
		<!-- get prev node in node-set -->
		<xsl:if test="preceding::BBB[1]">
			<xsl:text disable-output-escaping="yes">&lt;/Group2&gt;</xsl:text>
		</xsl:if>
	</xsl:template>
	<xsl:template name="setBeginTagBBBGroup2">
		<xsl:text disable-output-escaping="yes">&lt;Group2&gt;</xsl:text>
	</xsl:template>
</xsl:stylesheet>



Has anybody a idea how to do that?
Thanks








 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.