xsl-list
[Top] [All Lists]

Re: Extract values from first occurrence of a node

2003-07-16 09:40:34

  Recognize the first <B> with 12344 (substring from 1 with length 5) and 
  extract ABCD (substring from 7 with length 4), but ignore all other <B>

do you mean "ignore other B" or "ignore other B which start 12344"

in the first case

<xsl:template match="A">
 <xsl:apply-templates select="B[starts-with(.,'12344')][1]"/>
</xsl:template>

In the second interpretation of your question, you want to just
find the first B with a specified sort key (first five letters)
Then the answer of yesterday holds:

This is a "grouping problem" 

see

http://www.jenitennison.com/xslt/grouping/index.html

David


Specifically, set up a key of first five characters of a B node

<xsl:key name="x" match="B" use="substring(.,1,5)"/>

then muenchify your selection (See Jeni's site)

<xsl:template match="A">
 <xsl:apply-templates 
select="B[generate-id(.)=generate-id(key('x',substring(.,1,5)))]"/>
</xsl:template>

which will select the first B node with each unique first five letter
string.

ie the ones marked with !!
<A>
<B>12345 ABCD</B>!!
<B>12344 ABCD</B>!!
<B>12333 EFGH</B>!!
<B>12344 WXYZ</B>
</A>

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list