Wrox Programmer Forums
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2011, 05:07 PM
Registered User
 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Post XSLT

I have a file that contains data as:

Reporting for Date:2011-06-28
ID , Name , Type
1 , A , T1
2 , B, T1

I need to copy the date on each row, as a new column (as below)

ID , Name , Type Reporting Date
1 , A , T1, 2011-06-28
2, B, T1, 2011-06-28

How can I do this in XSLT 2.0?
 
Old July 6th, 2011, 02:16 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

XSLT does have some text parsing functions - specifically the unparsed-text(), tokenize() functions and the <xsl:analyze-string> instruction. This certainly isn't XSLT's strength, as it is usually used for processing XML input and creating XML output, but I'm sure what you are trying to do is possible.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old July 6th, 2011, 11:59 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First convert your data to XML, which is easily enough done using unparsed-text() and tokenize(). Then invert the rows and columns, which might be as simple as doing:

Code:
<xsl:variable name="table" select="."/>
<xsl:for-each select="1 to count(row[1]/cell)">
  <xsl:variable name="n" select="." as="xs:integer"/>
  <newrow>
     <xsl:copy select="$table/row/cell[$n]/>
  </newrow>
</xsl:for-each>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Another question about generating XSLT with XSLT danblick XSLT 2 July 16th, 2009 08:40 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
xslt with an xslt outputfile alleycat XSLT 4 February 20th, 2006 09:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.