Formatting rows in XSLT
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 8
- Joined: Tue Oct 02, 2012 4:53 am
Formatting rows in XSLT
I have the following XML and the intended out put is a pipe delimited file.
I'm trying to create a pipe delimited file using xslt.
I'had created the xslt with the following code
So far fine. I get the header records in pipe delimited format. Now when I put the reference for Employee_Data, all records gets displayed. I tried to create template reference and it still would not work. Either it displays all the records of all employees after the header is displayed and if I change it, I dont see any results but the header.
I'm new to writing xslt's. I know im making mistake on references. If anyone could help with sample code that would be great.
Here is the output I expect
1| 5
0001|John Smith
0002|John Carter
0003|Katie Smith
Thanks
Ash
Code: Select all
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<Header Record>
<page>1</page>
<records>5</records>
</Header Record>
<Employee_Data>
<Employee>
<Empl_Reference Descriptor="John Smith">
<ID type="Employee_ID">00001</ID>
</Empl_Reference>
<Employee_Details>
<Empl_ID>00001</Empl_ID>
<First_Name>John</First_Name>
<Last_Name>Smith</Last_Name>
</Employee_Details>
</Employee>
<Employee>
<Empl_Reference Descriptor="John Carter">
<ID type="Employee_ID">00002</ID>
</Empl_Reference>
<Employee_Details>
<Empl_ID>00002</Empl_ID>
<First_Name>John</First_Name>
<Last_Name>Carter</Last_Name>
</Employee_Details>
</Employee>
<Employee>
<Empl_Reference Descriptor="Katie Smith">
<ID type="Employee_ID">00003</ID>
</Empl_Reference>
<Employee_Details>
<Empl_ID>00003</Empl_ID>
<First_Name>Katie</First_Name>
<Last_Name>Smith</Last_Name>
</Employee_Details>
</Employee>
</Employee Data>
I'had created the xslt with the following code
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex"
xmlns:env=http://schemas.xmlsoap.org/soap/envelope/>
<xsl:template match="/">
<xsl:value-of select="/env:Envelope/env:Body/page"/> | <xsl:value-of
select="/env:Envelope/env:Body/records"/>
I'm new to writing xslt's. I know im making mistake on references. If anyone could help with sample code that would be great.
Here is the output I expect
1| 5
0001|John Smith
0002|John Carter
0003|Katie Smith
Thanks
Ash
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Formatting rows in XSLT
Hi,
The XML seems to have some mistakes that would make it not well formed and thus unusable. I'm guessing these are just spelling errors you've inserted here and the XML is actually fine otherwise.
e.g. <Header Record> can't have space in element name, so I'm guessing it's actually <Header_Record>.
Here's one way to do this:
Regards,
Adrian
The XML seems to have some mistakes that would make it not well formed and thus unusable. I'm guessing these are just spelling errors you've inserted here and the XML is actually fine otherwise.
e.g. <Header Record> can't have space in element name, so I'm guessing it's actually <Header_Record>.
Here's one way to do this:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:output indent="no" method="text"/>
<xsl:template match="/">
<xsl:value-of select="/env:Envelope/env:Body/Header_Record/page"/> | <xsl:value-of
select="/env:Envelope/env:Body/Header_Record/records"/>
<xsl:for-each select="/env:Envelope/env:Body/Employee_Data//Employee">
<xsl:value-of select="' '"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="Empl_Reference/ID"/> | <xsl:value-of select="Employee_Details/First_Name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="Employee_Details/Last_Name"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Formatting rows in XSLT
I've mentioned in the other thread: http://www.oxygenxml.com/forum/topic7275.html
The first one checks if there is a text node in that element and the second checks if there is a text node that contains something other than space characters.
Regards,
Adrian
I guess the explanation is actually backwards.To check for empty values:
<xsl:if test="preferredLastNameElement/text()">
To check for values that contain only space characters:
<xsl:if test="normalize-space(preferredLastNameElement/text())">
The first one checks if there is a text node in that element and the second checks if there is a text node that contains something other than space characters.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service