This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Arrays in XSLT for variables?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]