[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Integrated sort using different elements

Subject: Re: Integrated sort using different elements
From: Quinn Dombrowski <qdombrow@xxxxxxxx>
Date: Thu, 19 Feb 2009 10:13:03 -0600
Re:  Integrated sort using different elements
Hi Andy,

I wish it were so simple... the priority of the elements != the document order of the elements. If there's no monogr/author, then it jumps to analytic/author (which is before it in document order), then editor (somewhere else), and so on.

I'm using 2.0 (sorry, I should've mentioned that), so I'll try Michael's solution and let you know how it goes...

~Quinn

Houghton,Andrew wrote:
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: Thursday, February 19, 2009 10:49 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Integrated sort using different elements

<xsl:sort select="
monogr/author |
self::*[not(monogr/author)]/analytic/author |
self::*[not(monogr/author | analytic/author)]/monogr/editor |
self::*[not(monogr/author | analytic/author |
monogr/editor)]/monogr/title"/>
I think for XSLT 1.0 you can simplify that select to:

<xsl:sort select="(monogr/author|analytic/author)[1]"/>

I don't think so. That will select the first in document order, not the
first in the order of precedence defined in the requirement statement.

Maybe I misunderstood the requirements, but I thought it said that under the biblStruct element you wanted the first one that occurred to be sorted. So given:

<?xml version="1.0" ?>
<document>
  <biblStruct>
    <analytic>
      <author>Author Name 2</author>
      <title>Article Name 2</title>
    </analytic>
    <monogr>
      <author>Author Name 0</author>
      <title>Journal Title 0</title>
      <editor>Editor Name 0</editor>
    </monogr>
  </biblStruct>
  <biblStruct>
    <monogr>
      <author>Author Name 1</author>
      <title>Journal Title 1</title>
      <editor>Editor Name 1</editor>
    </monogr>
  </biblStruct>
</document>

and:

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
  <xsl:template match="biblStruct">
    <xsl:copy-of select="."/>
  </xsl:template>
  <xsl:template match="document">
    <xsl:copy>
      <xsl:apply-templates select="biblStruct">
        <xsl:sort order="ascending" data-type="text" select="(monogr/author|analytic/author)[1]"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="/">
    <xsl:apply-templates select="*[1]/self::document"/>
  </xsl:template>
</xsl:transform>

it should result in:

<?xml version="1.0" encoding="UTF-8"?>
<document>
   <biblStruct>
      <monogr>
         <author>Author Name 1</author>
         <title>Journal Title 1</title>
         <editor>Editor Name 1</editor>
      </monogr>
  </biblStruct>
   <biblStruct>
      <analytic>
         <author>Author Name 2</author>
         <title>Article Name 2</title>
      </analytic>
      <monogr>
         <author>Author Name 0</author>
         <title>Journal Title 0</title>
         <editor>Editor Name 0</editor>
      </monogr>
  </biblStruct>
</document>

So what did I misunderstand about the problem?


Andy.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.