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

Help with transforming unique set of data in XSLT 2.0

Subject: Help with transforming unique set of data in XSLT 2.0
From: Jack Bush <netbeansfan@xxxxxxxxxxxx>
Date: Tue, 27 Jul 2010 00:29:26 -0700 (PDT)
 Help with transforming unique set of data in XSLT 2.0
Hi All,

I am having difficulty get the following stylesheet to transform
unique set of 
data once:

1     <xsl:template match="/">
2
<xsl:apply-templates select="document('E:/employee.xml')/ns:html"/>
3
</xsl:template>
4
5     <xsl:template match="ns:html">
6        <employee>
7
<xsl:for-each
select="ns:body/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td
/ns:a">

8              <first_name><xsl:value-of
select="substring-before(@given_name,',')"/></first_name>
9
<surname><xsl:value-of select="@family_name"/></surname>
10
<sex><xsl:value-of select="@gender"/></sex>
11            </xsl:for-each>
12
</employee>
13    </xsl:template>

The following output generated duplicated
set of identical transformed data when 
using <xsl:for-each>:

<?xml
version="1.0" encoding="UTF-8"?>
<employee>
  <first_name>John</first_name>
<surname>smith</surname>
  <sex>M</sex>
  <first_name>Kelly</first_name>
<surname>Jones</surname>
  <sex>F</sex>
</employee>

<?xml version="1.0"
encoding="UTF-8"?>
<employee>
  <first_name>John</first_name>
<surname>smith</surname>
  <sex>M</sex>
  <first_name>Kelly</first_name>
<surname>Jones</surname>
  <sex>F</sex>
</employee>

I tried the following
changes after suspecting that the cause was from the 
<xsl:for-each>
statement:

1   <xsl:template match="/">
2   <xsl:apply-templates
select="document('E:/employee.xml')/ns:html"/>
3   </xsl:template>
4
5
<xsl:template match="ns:html">
6      <employee>
7        <xsl:variable
name="employee_data"
select="ns:body/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td
/ns:a"/>

8        <xsl:apply-templates select="$employee_data"/>
9
<first_name><xsl:value-of
select="substring-before(@title,',')"/></first_name>
10
<surname><xsl:value-of select="@href"/></surname>
11      <sex><xsl:value-of
select="@gender"/></sex>
12    </employee>
13 </xsl:template>

Below is the
output without using <xsl:for-each>:

<?xml version="1.0" encoding="UTF-8"?>
<employee>
  John Kelly
  <firstname />
  <surname />
  <sex/>>
</employee>
<?xml version="1.0" encoding="UTF-8"?>
<employee>
  John Kelly
  <firstname />
<surname />
  <sex/>>
</employee>

Any ideas on what is causing the
duplications and why is the second stylesheet 
picking up the firstnames of 2
separate xml documents in the wrong place?

The desire output is just a single
entry of each record such as the following:

<?xml version="1.0"
encoding="UTF-8"?>
<employee>
  <first_name>John</first_name>
<surname>smith</surname>
  <sex>M</sex>
  <first_name>Kelly</first_name>
<surname>Jones</surname>
  <sex>F</sex>
</employee>

Thanks a lot,

Jack

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.