[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: CSV output - select using xpath in variable
Subject: Re: CSV output - select using xpath in variable
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Fri, 11 Jun 2010 10:50:01 +0200
|
There are a couple of things that may go wrong: first make sure that
$message contains proper XML.
Then instrument/isin needs to be a string (put single quotes around it):
<xsl:variable name="path" select="'instrument/isin'" as="xs:string" />
Then it's as simple as
<xsl:value-of select="$message/message/trade/saxon:evaluate($path)" />
Another caveat:
You declared the types of the string variables. It's a good idea to also
declare the type of the message variable. In its current form, $message
holds a document-node(element(message)). If you declare it
<xsl:variable name="message" as="element(message)">
you will be able to use
<xsl:value-of select="$message/trade/saxon:evaluate($path)" />
This is another candidate place to look for an answer to the XSLT
developer's second-most frequently asked question: "Why doesn't my
expression select anything?".
(This question is only a corollary to the most frequently asked
question: "Why doesn't my template match?")
Cheers,
Gerrit
On 11.06.2010 10:02, Nick Leaton wrote:
Thanks. I'll have a look at evaulate.
At least 2.0 fixed the select from a parameter e.g.
$message/trade/instrument and you don't have to use a node set
function! :-)
Nick
On Fri, Jun 11, 2010 at 8:58 AM, Imsieke, Gerrit, le-tex
<gerrit.imsieke@xxxxxxxxx> wrote:
Dear Nick,
dynamic evaluation of XPath expressions is not (yet?) available in standard
XSLT 2. Have you looked at saxon:evaluate?
http://www.saxonica.com/documentation/extensions/functions/evaluate.html
Gerrit
On 11.06.2010 09:48, Nick Leaton wrote:
I'm trying to get a variant on the XSLT cookbook template to output csv
http://books.google.co.uk/books?id=6q50V7oykqEC&lpg=PP1&pg=PA240#v=onepage&q=delimiter&f=false
Page 240-241
It uses XSLT 2.0 and parts of it are quite neat.
I like the idea of importing a generic module, and then defining the
columns to export in the importing module.
I want to extend it to hand different delimiters, in the same way, and
also different line terminators.
The next extension is correctly quoting the output if it containts
quotes in strings etc.
So far, I can do this.
However, there is one problem I can't solve.
My input data is not regular, but CSV output needs to be regular. So I
want to defined the column names like this
<xsl:variable
name="columns"
select="
'trade',
'trade',
'currency',
'isin'
"
as="xs:string*"
/>
and the path names to get the data like this
<xsl:variable
name="nodepaths"
select="
'tradeid',
'trader',
'currency',
'instrument/isin'
"
as="xs:string*"
/>
The interesting part is the isin. To get the path from the input
fragment, it is an xpath.
So if I had
<xsl:variable name="path" select="instrument/isin" as="xs:string"/>
and
<xsl:variable name="message">
<message>
<trade>
<tradeid>1</tradeid>
<trader>Nick</trader>
<currency>USD</currency>
<instrument>
<isin>US0123456789</isin>
</instrument>
<trade>
</message>
<xsl:variable>
I want to do something like
<xsl:value-of select="$message/$path"/>
and have it return US0123456789
What's the best way?
--
Nick
--
Gerrit Imsieke
Geschdftsf|hrer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930
Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vvckler
--
Gerrit Imsieke
Geschdftsf|hrer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930
Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vvckler
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|