Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] only display if subnodes occur more than once

From: "Aron Bock" <aronbock@----------->
To:
Date: 7/3/2005 5:01:00 PM
Clemens,



You could use keys to identify the elements to output.  Thus, your input:



<root>
	<sub_a>
		<elem_1/>
		<elem_2/>
		<elem_3/>
	</sub_a>
	<sub_b>
		<elem_1/>
		<elem_2/>
		<elem_2/>
		<elem_2/>
		<elem_3/>
	</sub_b>
	<sub_c>
		<elem_1/>
		<elem_2/>
		<elem_3/>
	</sub_c>
</root>

Against this transform:



<?xml version="1.0" encoding="iso8859-1"?>

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



   <xsl:output method="xml" indent="yes"/>
   <xsl:strip-space elements="*"/>

   <xsl:key match="/*/*" name="kElems" use="*"/>



   <xsl:template match="root">
       <xsl:copy>
           <xsl:for-each select="*">
               <xsl:if test="count(key('kElems', .)) != count(*)">
                   <xsl:copy-of select="."/>
               </xsl:if>
           </xsl:for-each>
       </xsl:copy>
   </xsl:template>

</xsl:stylesheet>



Yields:



<?xml version="1.0" encoding="UTF-8"?>
<root>
 <sub_b>
   <elem_1/>
   <elem_2/>
   <elem_2/>
   <elem_2/>
   <elem_3/>
 </sub_b>
</root>

You could again use a key to identify and eliminate elements such as 
<elem_1>.  In fact *I* should do that, to match your required output ... but 
I need to use a composite key for that ... and it isn't coming to me right 
away.  If somebody else has more ready insight, please post.



Regards,



--A





From: "Prerovsky, Clemens" <Clemens.Prerovsky@xxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] only display if subnodes occur more than once
Date: Thu, 23 Jun 2005 12:06:42 +0200

Hi,



I'm stuck again with my XSL. My XML Structure looks like:



<root>
	<sub_a>
		<elem_1/>
		<elem_2/>
		<elem_3/>
	</sub_a>
	<sub_b>
		<elem_1/>
		<elem_2/>
		<elem_2/>
		<elem_2/>
		<elem_3/>
	</sub_b>
	<sub_c>
		<elem_1/>
		<elem_2/>
		<elem_3/>
	</sub_c>
</root>

The thing I want to do is display the element sub_b, because it has
subnodes which occur more than once (elem_2). I really have no idea how
to test for this - playing around for nearly two hours now. Im using a
loop like <xsl:for-each select="/root/*"> and the output should look
like

sub_b (this is the header)
elem_2
elem_2 (these are the 3 values of elem_2)
elem_2

Best regards,
Clemens Prerovsky

_________________________________________________________________

Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent