Wendell:
OK, I was looking at using keys as well but the problem I was having (and am
still having regardless of approach) is when I need to do compound matching.
I dont have an AND operator (do I?) to say I want to extract the first <B>
who's substring() == val1 && substring() == val2 && substring() == val3...
I'd like the use to be multiple substring matched.
I definitely see the approach...makes sense. Thinking about how I've been
doing XSL for the last 2 weeks...I could have saved myself alot of code to
use some of these more concise approaches! ;)
Guess thats what learning is all about! Good thing I have you guys to help
me along!
Please let me know what you think about the multiple substring match for USE
in KEYs.
Thanks,
Matt
From: Wendell Piez <wapiez(_at_)mulberrytech(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Extract values from first occurrence of a node
Date: Wed, 16 Jul 2003 12:31:26 -0400
Matt,
Although this can be done without them, keys are very useful in XSLT for
this kind of operation.
You'd declare a key to match <B> elements, with the string value you care
about (your substring) as the key value:
<xsl:key name="B-by-string" match="B" use="substring(.,1,5)"/>
Then the XPath "key('B-by-string','12344')" will get you all <B> elements
that have that key value, while "key('B-by-string','12344')[1]" will get
you the first of these (in document order). You could of course use a
variable as that second argument.
Part of getting your head around XSLT's non-proceduralness is in learning
the various ways nodes can be selected, without having to run processes
over the set (or find out what processes may have already been run -- in a
side-effect free system this isn't appropriate, desirable or generally
possible).
Cheers,
Wendell
At 12:09 PM 7/16/2003, you wrote:
I am trying to translate XML via XSL/XSLT need to specifically extract the
values from the first occurrence of a particular node and ignore the rest
of that same node.
I was attempting to use preceding-sibling::nodeset/node to verify if the
match has already been made, but having little luck because I not only
need to match the node but match substrings of the node's value.
Example XML:
<A>
<B>12345 ABCD</B>
<B>12344 ABCD</B>
<B>12333 EFGH</B>
<B>12344 WXYZ</B>
</A>
What I need to do:
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>
This is a very basic example, the XML I am working with is a bit more
complicated and it is being translated via XSL-FO for PDF generation.
The biggest problem I am having with XSL/XSLT is detaching from my
procedural language experience! From my experience, I am having success
in mapping singlular nodes but more difficulty when trying to accomplish
"decision logic" in a non-procedural manner.
Any suggestions or recommended reads would be great.
Thanks,
Matt
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list