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

Re: variable never matched hardcoded string

Subject: Re: variable never matched hardcoded string
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Thu, 25 Jul 2002 06:39:31 +0200
xslt variable string space
Hello Maizatul,

you have some strange things in your code - maybe these are only typos in the mail.

Maizatul Alma Elias wrote:
Hi,
Basically, what I'm trying to do is to assign each value of <dataValue>
into a particular variable based on it attribute(fid).
My problem is, the ** part never matched and also I would like to know
if this is the right thing to do it.

Thanks.

maizatul

xml
----
<message>
<dataContent>
<dataValue fid="R055">706</dataValue>
<dataValue fid="R039">1066</dataValue>
......

</dataContent>
</message>

xslt
---
<xsl:template match="message">

    <xsl:variable name="ABC">
        <xsl:call-template name="xyz">
           <xsl:with-param name="p_Code">stock</xsl:with-param>
        </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="ABC">
        <xsl:call-template name="xyz">
           <xsl:with-param name="p_Code">action</xsl:with-param>
        </xsl:call-template>
    </xsl:variable>

     .......
     .......

</xsl:template>

In this template you declared twice the variable "ABC", what's an error.


Furthermore you are creating Result Tree Fragments in your parameters, where you want to have a string. That's not really bad, but can be avoided by writing <xsl:with-param name="xyz" select="'action'"/>.

For information on RTF see http://www.w3.org/TR/xslt#section-Result-Tree-Fragments, http://www.dpawson.co.uk/xsl/xslvocab.html#d59e410 and http://www.dpawson.co.uk/xsl/xslvocab.html#rtf.

<xsl:template match="dataContent/dataValue">

Should this template be named 'xyz'??


<xsl:param name="p_Code">

<xsl:apply-templates select="dataContent/dataValue"/>

What template do you apply on these nodes?


<xsl:if test = "normalize-space($p_code) = 'stock')"> **

right parenthesis? ^^^


<xsl:if test = "consist(@fid,'039')">

There is no function consist(), I assume you mean contains().


               <xsl:value-of select=(.)>
          </xsl:if>
     </xsl:if>
     <xsl:if test = "normalize-space($p_code) = 'action')">  **
          <xsl:if test = "consist(@fid,'055')">
               <xsl:value-of select=(.)>
          </xsl:if>
     </xsl:if>
     .........

</xsl:template>

Why not simply


<xsl:template match="message">
<xsl:variable name="ABC" select="dataContent/dataValue[contains(@fid, '039')"/>
<xsl:variable name="DEF" select="dataContent/dataValue[contains(@fid, '055')"/>
...
</xsl:template>


Or if you really want to collect all cases in an extra template:

<xsl:template match="message">
  <xsl:variable name="ABC">
    <xsl:apply-templates select="dataContent/dataValue">
      <xsl:with-param name="p_Code" select="'stock'"/>
    </xsl:apply-templates>
  </xsl:variable>
  <xsl:variable name="DEF">
    <xsl:apply-templates select="dataContent/dataValue">
      <xsl:with-param name="p_Code" select="'action'"/>
    </xsl:apply-templates>
  </xsl:variable>
</xsl:template>

<xsl:template match="dataContent/dataValue">
  <xsl:param name="p_Code" select="''"/>
  <xsl:choose>
    <xsl:when test="$p_code = 'stock' and contains(@fid, '039')">
      <xsl:value-of select="."/>
    </xsl:when>
    <xsl:when test="$p_code = 'action' and contains(@fid, '055')">
      <xsl:value-of select="."/>
    </xsl:when>
  </xsl:choose>
</xsl:template>

But I don't see really sense in the second way, maybe you have to explain your problem a bit more.

Hope this helps,

Joerg


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.