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

Re: conditional position()

Subject: Re: conditional position()
From: Bruce D'Arcus <bdarcus@xxxxxxxxx>
Date: Wed, 20 Apr 2005 17:42:33 -0400
conditional type i
On Apr 20, 2005, at 5:08 PM, Dimitre Novatchev wrote:

I know why the above doesn't work, but I'm not sure how to fix it. Am
using XSLT 2.0.

What does "doesn't work" means?

It means it measures the position in relation to all name elements, rather than just the ones that fit my condition ...


The (global) contributor-role variable is:

<xsl:variable name="primary-contributors" select="('author', 'editor',
'creator', 'reporter')"/>

Sorry, but this variable is named "primary-contributors", not "contributor-role".

Sorry, was obviously in a hurry. I don't have the code in front of me, but the contributor-role variable returns "primary" if the value of roleTerm matches the list in the primary-contributors variable.


Source example would be:

<name type="personal">
 <namePart type="given">Jane</namePart>
 <namePart type="family">Doe</namePart>
 <role>
   <roleTerm>translator</roleTerm>
 </role>
</name>
<name type="personal">
 <namePart type="given">Jane</namePart>
 <namePart type="family">Doe</namePart>
 <role>
   <roleTerm>author</roleTerm>
 </role>
</name>
<name type="personal">
 <namePart type="given">John</namePart>
 <namePart type="family">Smith</namePart>
 <role>
   <roleTerm>translator</roleTerm>
 </role>
</name>

The position of the second name element with the author role should be
'1' and it should  be 'true' for last().  In other words, processing
should completely ignore the name elements that contain roles other
than those that are "primary."

Not clear. Could you, please, define more precisely?

My code is a couple/few thousand lines, so am trying to keep it as simple as possible.


Let's say I have this document:

<doc>
  <x type="a"/>
  <x type="b"/>
  <x type="a"/>
  <x type="b"/>
<doc>

How can I only process the x elements with type attribute value of "b", and have position() and last() only apply to those conditions?

In other words, how do I trick the processor into thinking the above is:

<doc>
  <x type="b"/>
  <x type="b"/>
<doc>

... such that the second occurrence would have a position of 2, and would be the last?

The concrete issue is formatting names. So I need to format all authors, for example, as:

Doe, John
Doe, John and Jane Smith
Doe, John, Jane Smith and James Jones

So I need to know the position of any given *author* name.

Clearly it would help if my xml was designed differently, but I don't have much control over that.

If the above still isn't clear, I'll try to post some templates later.

Thanks,
Bruce

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.