Re: [xsl] Manipulating elements depending on the existence of sub-elements

Subject: Re: [xsl] Manipulating elements depending on the existence of sub-elements
From: "Adil Ladhani" <dillio@xxxxxxxxx>
Date: Tue, 11 Mar 2008 15:39:17 -0400
Nice! The "following-sibling" function was exactly what I was looking
for, thank you very much Michael. My poorly parsed data now has it's
rightfully owned unique id information.

My only remaining issue is that the position() count is inaccurate for
the problematic "Item" (as it is contained in 2 "Item" elements rather
than one, so the count will be 1, 2, 3, 1, 2, 3 instead of 1, 2, 3, 4,
5, 6) but I'm guessing there isn't much I can do about this in XSL?
(since position()'s value *is* technically accurate, and I'm actually
trying to manipulate it)

If nothing can be done about it in XSL I can probably add a count in
.net prior to bulk loading.

Adil



On Tue, Mar 11, 2008 at 3:13 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> > So my XSL question is: am I able to check for the existence
> > of a "UniqueInfo" element within an "Item" element, and if
> > one does not exist, use the UniqueInfo element that the next
> > "Item" contains?
>
> Try select="(UniqueInfo | following-sibling::Item[1]/UniqueInfo)[1]
>
> for example, in a variable:
>
> <xsl:variable name="uniqueInfo"
>  select="(UniqueInfo | following-sibling::Item[1]/UniqueInfo)[1]"/>
>
> This relies on the fact that the result of a union (|) is always in document
> order, and "[1]" will therefore select whichever comes first: the UniqueInfo
> child of this item, or the UniqueInfo child of the next item.
>
> Michael Kay
> http://www.saxonica.com/

Current Thread