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

Arrays in XSLT for variables?

Subject: Arrays in XSLT for variables?
From: "Maulik Modi" <mxmodi@xxxxxxxxxxxxxxx>
Date: Mon, 19 Feb 2001 17:09:52 -0600
xslt array
Hi,

I am trying to parse a XML doc1, extract a particular node value from XML
doc 1and then pass this string as an XPATH expression to be evaluated in a
separate XML doc 2.  I can build the dynamic XPATH using the evaluate() fn.
Next I want to do a conditional test to compare both the parsed value from
doc1 and the validated value from doc2 for each <Node_path>'s and
<Node_value> pairs. If the test returns true, I want to process all the
<URL>'s in the following-siblings.

WHAT I WANT:
For example, in the following XML, I have two <Node_path> and <Node_value>
pairs in the first child, I want to test if the values for both the pairs
are true and then process the three <URL>'s for it., meaning 3 times.

WHAT I have working:
In the following XML, I have two <Node_path> and <Node_value> pairs in the
first child, and if both text are valid, it processes each <URL> under it,
meaning six times!

Any help is appreciated. Can I store each pair in an array and refer to it
later when I need to?

My XML doc1 (called BER2.xml in the stylesheet) is:

<CHANNEL>
  <EVENT name="steve14nov">
    <NODE>

<Node_path>//DATA/PARAMETERS/PARAMETER/TimeSheet/EmpUserID</Node_path>
      <Node_value>txtester</Node_value>

<Node_path>//DATA/PARAMETERS/PARAMETER/TimeSheet/BeginWeek</Node_path>
      <Node_value>11/14/01</Node_value>
      <URL>http://url1</URL>
      <URL>http://url2</URL>
      <URL>http://url3</URL>
    </NODE>
    <NODE>
      <Node_path>//DATA/PARAMETERS/PARAMETER/some/other/node/</Node_path>
      <Node_value>txtester2</Node_value>
      <URL>http://url1</URL>
      <URL>http://url2</URL>
    </NODE>
  </EVENT>
</CHANNEL>

default XML passed to XSLT (refered to as doc2 above):

<MESSAGE>
<!--bunch of xml tags here ignored -->

<DATA>
  <PARAMETERS>
    <PARAMETER>
    <TimeSheet>
    <EmpUserID>txtester</EmpUserID>
    <BeginWeek>11/14/01</BeginWeek>
    <EndWeek>11/20/01</EndWeek>
    <Sun>1</Sun>
    <Mon>2</Mon>
    <Tue>3</Tue>
    <Wed>4</Wed>
    <Thu>5</Thu>
    <Fri>6</Fri>
    <Sat>7</Sat>
    <LastDate>01/01/01</LastDate>
    <UpdateUserId>admin</UpdateUserId>
    </TimeSheet>
    </PARAMETER>
  </PARAMETERS>
  </DATA>
</MESSAGE>


Snippet XSL code:

  <xsl:variable name="tempdoc" select="document('BER2.xml')/CHANNEL" />
  <xsl:variable name="chandoc" select="." />

  <xsl:template match="/">
    <!--some other code for presentation deleted here-->

   <xsl:for-each select="$tempdoc//Node_path">

         <xsl:variable name="npath" select="." />
         <xsl:variable name="nvalue" select="following-sibling::Node_value"
/>
         <xsl:variable name="urls" select="following-sibling::URL" />

      <xsl:for-each select="$chandoc//DATA" >
       <xsl:variable name="parsed" select="saxon:evaluate($npath)" />
       <xsl:variable name="valid" select="$nvalue" />

       <xsl:if test="$parsed=$valid">
        <URL><xsl:value-of select="$urls" /></URL>
       </xsl:if>
      </xsl:for-each>

  </xsl:for-each>
</xsl:template>


 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.