RE: [xsl] example for xsl:output saxon:next-in-chain

Subject: RE: [xsl] example for xsl:output saxon:next-in-chain
From: <uap001@xxxxxxxxx>
Date: Thu, 10 Feb 2005 09:55:40 -0800 (PST)
This is in reply to Michael Kay's response to my
earlier post. Somehow, I don't get messages back from
the list - so, not able to reply to the original post.

I created some sample files to test this, since my
xslt files are too big, and I am not able to translate
them also by using two pass xslt

========= XML file xmldata.xml that I want to
translate ==========
<?xml version='1.0' encoding='UTF-8'?>
<Test>
   <Sample>Test Sample</Sample>
   <Details>
   <Name>name1</Name>
   <Count>22</Count>
 </Details>
<Details>
   <Name>name2</Name>
   <Count>3</Count>
 </Details>
<Details>
   <Name>name3</Name>
   <Count>4</Count>
 </Details>
<Details>
   <Name>name1</Name>
   <Count>1</Count>
   </Details>
</Test>

===================The main xslt file main.xsl I use
for translation ============
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:saxon="http://icl.com/saxon"; version="1.0">


<!-- this stylesheet runs the first pass and hands the
     result to be run with the second pass -->

<xsl:import href="first.xsl"/>

<xsl:output method="xml" indent="yes"
saxon:next-in-chain="second.xsl"/>

</xsl:stylesheet>

=========== first.xsl file =============
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0" >
	<xsl:output method="xml" indent="yes"
encoding="ISO-8859-1" />

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

<TT>
<xsl:for-each select="Details">
<XX>
<Name>
<xsl:value-of select="Name"/>
</Name>
<Count>
<xsl:value-of select="Count"/>
</Count>
</XX>
</xsl:for-each>
</TT>
</xsl:template>
</xsl:stylesheet>


============= second.xsl =================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0" >
	<xsl:output method="xml" indent="yes"
encoding="ISO-8859-1" />

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

<xsl:for-each select="XX">
<XX1>
<Count>
<xsl:value-of select="Count"/>
</Count>
</XX1>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

=======================
By doing the following command to test the traslation,
I am doing "java org.apache.xalan.xslt.Process -in
xmldata.xml -xsl main.xsl -out final.out"

By doing this, I get following in final.out
<?xml version="1.0" encoding="ISO-8859-1"?>
<TT>
<XX>
<Name>name1</Name>
<Count>22</Count>
</XX>
<XX>
<Name>name2</Name>
<Count>3</Count>
</XX>
<XX>
<Name>name3</Name>
<Count>4</Count>
</XX>
<XX>
<Name>name1</Name>
<Count>1</Count>
</XX>
</TT>

======= However, I expect it to be ===========
<?xml version="1.0" encoding="ISO-8859-1"?>
<XX1>
<Count>22</Count>
</XX1>
<XX1>
<Count>3</Count>
</XX1>
<XX1>
<Count>4</Count>
</XX1>
<XX1>
<Count>1</Count>
</XX1>

Not sure what am I doing wrong. Thanks for all your
help.








		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

Current Thread