Solved

Get 1st row of data into a variable

Posted on 2010-08-17
8
392 Views
Last Modified: 2013-11-18
I have an xml file as seen below: what I need to get is the values in the first row to set some values in before I process all the rows in the row template.  

I can not figure out how to getl the data in the first row by itself before I run the row template.

XML -data
<?xml version="1.0"?>
<document>
  <row>
    <column1>20100810</column1>
    <column2>20100815</column2>
    <column3>20100817</column3>
    <column4>WLP_PCN_SL_regular_20100816.out</column4>
  </row>
  <row>
    <column1>01300</column1>
  </row>
  <row>
    <column1>01820</column1>
  </row>
  <row>
    <column1>02282</column1>
  </row>
</document>

XSL
  <xsl:template match="/">
    <xsl:apply-templates select="document"/>
  </xsl:template>

  <xsl:template match="document">
  <xsl:variable name="vNameOfDataFile" select="row/@column1"/>

          <ProcessStartWorkDate>
            <Date><xsl:value-of select="$vNameOfDataFile"/></Date>
          </ProcessStartWorkDate>
           
      <xsl:for-each select="row">
        <xsl:apply-templates select="."/>
      </xsl:for-each>
0
Comment
Question by:johnth1957
  • 5
  • 3
8 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 33455455
<xsl:variable name="vNameOfDataFile" select="row[1]/@column4"/>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 33455644
the [1] tells you that you need the first row
the name of data file seems to be in column four
note that this variable can only be used in this template,
if you want a global variable put this at the highest level

<xsl:variable name="vNameOfDataFile" select="/document/row[1]/@column4"/>
0
 

Author Comment

by:johnth1957
ID: 33455773
Thanks, I just tried that and still not getting a value in that variable .
0
 

Author Comment

by:johnth1957
ID: 33455824
Yes that is the correct column for the variable but I was just trying to get something to work in case I was pulling off another record.
I am declaring and using the variable in the same template.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 33455827
of course, the @ should not be there, error in copy and pasting from your mistake, sorry
    <xsl:variable name="vNameOfDataFile" select="/document/row[1]/column4"/>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 33455841
or
<xsl:template match="document">
    <xsl:variable name="vNameOfDataFile" select="row[1]/column4"/>
    <xsl:value-of select="$vNameOfDataFile"/>
</xsl:template>
0
 

Author Closing Comment

by:johnth1957
ID: 33455904
Thanks!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 33455914
welcome
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Challenge to XML Gurus, (XML link downloads blank data while data exists) 10 55
API Soap Calls 4 85
Word files to Wordpress Posts 2 43
cookies analysis tools 2 65
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now