Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 May 31st, 2013, 03:35 PM
Registered User
 
Join Date: May 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default transpose rows to column data

<element>
<value>123</value>
<value>456</value>
<value>789</value>
</element>


I want output like this

<row>369</row>
<row>258</row>
<row>147</row>

help required!!!

Thanks for your reply Martin, But I am using xalan processor, can you provide alternate approach for this. thanks in advance.

Last edited by MUTHU; June 2nd, 2013 at 07:45 AM..
 
Old June 1st, 2013, 08:57 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Here is one way to do it with XSLT 2.0:
Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs">

<xsl:output indent="yes"/>

<xsl:template match="element">
  <xsl:variable name="length" select="string-length(value[1])"/>
  <xsl:for-each-group select="value/string-to-codepoints(.)" group-by="position() mod $length">
    <xsl:sort select="position()" order="descending"/>
    <row>
      <xsl:value-of select="codepoints-to-string(current-group())"/>
    </row>
  </xsl:for-each-group>
</xsl:template>

</xsl:stylesheet>
That transforms
Code:
<element>
<value>123</value>
<value>456</value>
<value>789</value>
</element>
into
Code:
<row>369</row>
<row>258</row>
<row>147</row>
You can run XSLT 2.0 with Saxon 9 or AltovaXML or XmlPrime.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Transpose of data in a table... budha Oracle 0 February 16th, 2010 10:44 AM
Transpose Rows/Pivot Table prasanta2expert Access 0 April 26th, 2008 01:01 AM
Transpose the data yogeshyl Excel VBA 2 September 15th, 2007 11:09 AM
How to Transpose this type data jaincafe Access 1 November 27th, 2006 05:58 AM
Transpose Rows JpJoe Access 10 March 17th, 2005 08:15 AM





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