![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - sorting by attribute value [Thread Next] Re: sorting by attribute valueTo: 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> | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
