Get 1st row of data into a variable

Posted on 2010-08-17
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"?>

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

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

            <Date><xsl:value-of select="$vNameOfDataFile"/></Date>
      <xsl:for-each select="row">
        <xsl:apply-templates select="."/>
Question by:johnth1957
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 60

Expert Comment

by:Geert Bormans
ID: 33455455
<xsl:variable name="vNameOfDataFile" select="row[1]/@column4"/>
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"/>

Author Comment

ID: 33455773
Thanks, I just tried that and still not getting a value in that variable .
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.


Author Comment

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.
LVL 60

Accepted Solution

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"/>
LVL 60

Expert Comment

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

Author Closing Comment

ID: 33455904
LVL 60

Expert Comment

by:Geert Bormans
ID: 33455914

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML Data Missing in PHP SimpleXML 8 83
Where do I learn ES6? 3 81
customizing windows 10 taskbar and startmenu 2 40
How to build a web site 17 59
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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