xsl-list
[Top] [All Lists]

Re: [xsl] What is the simplest method for using xsl:sort without losing attribute names and values?

2008-07-20 10:58:48
Hello Martin,

After I was told you had answered, I found your email in the junk. Sorry I missed it the first time.

I am reconstructing the original sequence of journal articles from a <List> of non-sequential <Items>. My task is to sort the several hundred <Items>in a <List> container by Year, Issue Number, and Page.

In the example below, only one <Item> is shown. I tried the template you suggested. As before, in the output I get a concatenation of the attribute values in the tags that have attributes. See <Cat> and <Person> illustrated as input and output below:

Thanks,
Mark

You suggested:
<xsl:template match="*">
       <xsl:copy>
           <xsl:apply-templates select="@*"/>
           <xsl:apply-templates>
               <xsl:sort select="Article/Year" />
               <xsl:sort select="Article/IssueNumber"/>
               <xsl:sort select="Article/Page" />
           </xsl:apply-templates>
       </xsl:copy>
   </xsl:template>

My input:
<List>
<Item>
       <Cat pofis="4" pofis-number="116"/>
       <Subject>Errors</Subject>
       <Subject>Color Errors</Subject>
       <Subject>Olympic Games. Atlanta</Subject>
       <Article>
           <Person>Fritz, Zdenek</Person>
           <Person is-author="false">Kleskovic, Peter Z.</Person>
           <Title>Imperfect color se-tenant</Title>
           <Year>2000</Year>
           <IssueNumber>1</IssueNumber>
           <IssueName>Jan/Feb</IssueName>
           <Page>10</Page>
       </Article>
   </Item>
</List>

The output from your template:
<List>
<Item>
       <Cat>4116</Cat>
       <Subject>Errors</Subject>
       <Subject>Color Errors</Subject>
       <Subject>Olympic Games. Atlanta</Subject>
       <Article>
           <Person>Fritz, Zdenek</Person>
           <Person>falseKleskovic, Peter Z.</Person>
           <Title>Imperfect color se-tenant</Title>
           <Year>2000</Year>
           <IssueNumber>1</IssueNumber>
           <IssueName>Jan/Feb</IssueName>
           <Page>10</Page>
       </Article>
   </Item>
</List>



--~------------------------------------------------------------------
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>
--~--