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

Re: Newbie - trying to extract specific values from XM

Subject: Re: Newbie - trying to extract specific values from XML file.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 19 Mar 2004 16:59:29 +0000
laquo xsl
Hi Julian,

> I have a long html file (see http://hq.tvw.net/template.html)
> that includes a mass of merge codes from an old program.

What I'd suggest is that you set up a key that retrieves the <Answer>
element with a particular name. The key would look like:

<xsl:key name="answers" match="Answer" use="@name" />

Then anywhere in the template where you have something like:

  &laquo;SETstd&raquo;

you can use, instead:

  <xsl:apply-templates select="key('answers', 'SETstd')" />

The call to the key() function retrieves the <Answer> element whose
name attribute has the value 'SETstd'. The <xsl:apply-templates>
instruction applies templates to it. You then need templates that look
like:

<xsl:template match="Answer[@name = 'SETstd']">
  SETstd is <xsl:value-of select="TFValue" />
</xsl:template>

to get the appropriate text for the given answer.

You can similarly use the key to retrieve the <Answer> elements where
they're tested in IF statements within the current template. For
example:

  &laquo;IF Setstd = FALSE&raquo;

can be replaced by:

  <xsl:if test="key('answers', 'SETstd')/TFValue = 'false'">

Note that you have to do a bit of work to identify what descendant of
the <Answer> element you need to look at in these tests, since it
depends on the structure of the XML that you're using (whether the
<Answer> element contains a <RptValue> element, a <TFValue> element,
a <TextValue> element or something else.
  
The key is a very efficient way to get at the <Answer> elements based
on their name. Given that you already have the HTML template written
in a 'pull' way, I think that this approach is going to be easier to
use than a more 'push' method of applying templates to all the
<Answer> elements and just having templates to match them.
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


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.