Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: sorting by attribute value

From: dvdastor@-----.---
To: NULL
Date: 2/2/2007 11:54:00 AM

On Feb 2, 1:36 pm, dvdas...@yahoo.com wrote:
> Greetings,
>
> I need to sort this XML by the value in the sequence attribute and I
> was hoping for a little help as the XSL i have created is not doing
> the job.
>
> <AnswerKey>
>      <question id="100">
>           <fragment sequence="3">Some Text</fragment>
>           <fragment sequence="1">Some Text</fragment>
>           <fragment sequence="2">Some Text</fragment>
>     </question>
>
>      <question id="101">
>           <fragment sequence="3">Some Text</fragment>
>           <fragment sequence="2">Some Text</fragment>
>           <fragment sequence="1">Some Text</fragment>
>     </question>
> </AnswerKey>
>
> I need each question element to contain the fragment elements, but
> sorted numerically by sequence.
>
> Here is the XSL I am using:
>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
> Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
>    <xsl:template match="/">
>          <AnswerKey>
>              <xsl:for-each select="AnswerKey/question">
>                  <xsl:for-each select="fragment">
>              <xsl:sort data-type="text" select="@sequence"/>
>                    <xsl:copy-of select="."/>
>          </xsl:for-each>
>         <xsl:copy-of select="."/>
>              </xsl:for-each>
>            </AnswerKey>
>      </xsl:template>
> </xsl:stylesheet>
>
> I think the problem is the second "copy-of".  I can't seem to get the
> syntax correct for what I am looking to do. Can anyone help?  Thanks!



I was actually able to find out what I did wrong.  Thanks to anyone
that looked at it and tried to help.  Here is a copy of the XSL
stylesheet i use now to accomplish exactly what I want.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:output omit-xml-declaration="yes" indent="yes"/>
	<xsl:strip-space elements="*"/>


	<xsl:template match="node()|@*">
		<xsl:copy>
			<xsl:apply-templates select="node()|@*"/>
		</xsl:copy>
	</xsl:template>


	<xsl:template match="question">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates>
				<xsl:sort select="@sequence" data-type="number"/>
			</xsl:apply-templates>
		</xsl:copy>
	</xsl:template>


</xsl:stylesheet>




transparent
Print
Mail
Digg
delicious
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