xsl-list
[Top] [All Lists]

[xsl] sort question

2006-09-07 23:46:25
Dear experts!

I get for example the following xml:

<pub>
 <segment>
  <text xml:lang="en">fdasfds</text>
  <text xml:lang="de">fdasfds</text>
  <text xml:lang="fr">fdasfds</text>
 </segment>
 <segment>
  <text xml:lang="fr">fdasfds</text>
  <text xml:lang="de">fdasfds</text>
  <text xml:lang="en">fdasfds</text>
 </segment>
 <segment>
  <text xml:lang="fr">fdasfds</text>
  <text xml:lang="en">fdasfds</text>
  <text xml:lang="de">fdasfds</text>
 </segment>
 ...
</pub>

For other steps I always need the german (de) then the english (en) and at 
least the french (fr) text.
I tried to use xsl:sort to sort the xml:lang attribute but I don't get it to 
work :-(

The result for the example xml should look like this:

<pub>
 <segment>
  <text xml:lang="de">fdasfds</text>
  <text xml:lang="en">fdasfds</text>
  <text xml:lang="fr">fdasfds</text>
 </segment>
 <segment>
  <text xml:lang="de">fdasfds</text>
  <text xml:lang="en">fdasfds</text>
  <text xml:lang="fr">fdasfds</text>
 </segment>
 <segment>
  <text xml:lang="de">fdasfds</text>
  <text xml:lang="en">fdasfds</text>
  <text xml:lang="fr">fdasfds</text>
 </segment>
 ...
</pub>

I have tried the following stylesheet (and some other combinations):

<xsl:stylesheet ...>
 <xsl:template match="/">
   <xsl:choose>
         <xsl:when test="name() != segment">
                <xsl:apply-templates select="node() | @*"/>
        </xsl:when>
        <xsl:otherwise>
                <xsl:for-each select="//node()[(_at_)xml:lang]">
                        <xsl:apply-templates select="node() | @*">
                                <xsl:sort select="@xml:lang" order="ascending"/>
                        </xsl:apply-templates>
                </xsl:for-each>
                <xsl:apply-templates select="node() | @*"/>
        </xsl:otherwise>
   </xsl:choose>
</xsl:template>
        <!--
        -->
<xsl:template match="node() | @*">
        <xsl:copy>
                <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
</xsl:template>
</xsl:stylesheet>

What's wrong here?

Thanks
Markus
-- 


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>