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

RE: Variables and Values

Subject: RE: Variables and Values
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Tue, 23 Mar 2004 19:15:25 +0100
xsl variables
> -----Original Message-----
> From: Julian Voelcker [mailto:asp@xxxxxxx]
>

Hi,

> I am trying to replicate some programming logic in my template along
> the following lines:
>
> 1. The XML file holds data from a questionnaire.
> 2. At the beginning of a template I want to test to see if a particular
> question has been answered - if it has it will either be true or false
> - if it hasn't been answered there will be no value.

Does this necessarily *have* to take place at the beginning?

Say you have a structure like:

<doc>
  <question nr="1" answer="true" />
  <question nr="2" />
  <question nr="3" answer="true" />
</doc>

If you define two separate templates, like:

<xsl:template match="question[@answer]">
  <xsl:copy-of select="." />
</xsl:template>

<xsl:template match="question[not(@answer)]">
  <xsl:copy>
    <xsl:copy-of select="@*" />
    <xsl:attribute name="answer">
       <xsl:value-of select="'true'" />
    </xsl:attribute>
  </xsl:copy>
</xsl:template>

Then the following instruction:

<xsl:apply-templates select="doc/question" />

will do what is necessary. The questions having an answer attribute will
just be copied, the questions without an answer attribute will be copied to
the result tree with addition of an answer attribute set to 'true'.


Hope this helps!

Cheers,

Andreas

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.