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

Re: Interesting issue

Subject: Re: Interesting issue
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Sun, 24 Nov 2002 14:16:17 +0100
kasarabada
Hello Nischal,

this is really an extreme demand. I see only this string:

<data>SudhakarJalli030719751809Bigbenddrmilpitasca95035Rajeevkasarabada032719751788lowerbenddrivesanjoseca94523</data>

Where do you know from (or where should the XSLT processor or JavaScript know from), where to divide the strings in substrings? There seems to be no delimiter and no fixed number of characters.

In every case the logic you implemented in JS can be implemented in XSLT with a recursive template:

<xsl:template match="/Customers">
  <Customers>
    <xsl:call-template name="customer">
      <xsl:with-param name="data" select="data"/>
    </xsl:call-template>
  </Customers>
</xsl:template>

<xsl:template name="customer">
  <xsl:param name="data" select="''"/>
  <xsl:if test="string(data)">
    <Customer>
      <FirstName>
        <xsl:value-of select="substring($data, 1, 15)"/>
      </FirstName>
      <LastName>
        <xsl:value-of select="substring($data, 16, 1)"/>
      </LastName>
      <Street>
        <xsl:value-of select="substring($data, 17, 1)"/>
      </Street>
      <City>
        <xsl:value-of select="substring($data, 18, 1)"/>
      </City>
      ...
      and so on
      ...
    </Customer>
    <xsl:call-template name="customer">
      <xsl:with-param name="data" select="substring($data, 20)"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

But as I said there is no logic for the string length. Where do you want to get it from?

Regards,

Joerg

Nischal Muthana wrote:
Hi All

I am transforming xml to xml using an xsl with Xalan
XSLT processor. But I am getting the resulting xml as
string instead of


nodelist.

test.xsl
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lxslt="http://xml.apache.org/xslt"


xmlns:result="http://www.example.com/results"
extension-element-prefixes="result" version="1.0">
<xsl:output method="xml"/>
	<lxslt:component prefix="result"
functions="GetCopyBookData">
	<lxslt:script lang="javascript">
	function GetData(Data)
	{
		var x1 = 0;
		var x2 = 0;
		var result;
		for(var i = 1;i < 3; i++)
		{
			var s = "<Customers><FirstName>";
			x1 = x2;
			x2 = x1 + 15;
			s = s + Data.substring(x1,x2) + "</FirstName>";
			s = s + "<LastName>";
			x1 = x2;
			x2 = x1 + 1;
			s = s + Data.substring(x1,x2) + "</LastName>";
			s = s + "<StreetNum>";
			x1 = x2;
			x2 = x1 + 1;
			s = s + Data.substring(x1,x2) + "</StreetNum>";
			s = s + "<Street>";
 			x1 = x2;
			x2 = x1 + 1;
			s = s + Data.substring(x1,x2) + "</Street>";
			s = s + "<City>";
			x1 = x2;
			x2 = x1 + 1;
			s = s + Data.substring(x1,x2) + "</City>";
			s = s + "<State>";
			x1 = x2;
			x2 = x1 + 1;
			s = s + Data.substring(x1,x2) + "</State>";
			s = s + "<Zip>";
			x1 = x2;
			x2 = x1 + 1;
			s = s + Data.substring(x1,x2) + "</Zip>";
			result = result + s;
		}
		return result;
	}
	</lxslt:script>
	</lxslt:component>
	<xsl:template match="/">
		<xsl:variable name="Data" select="data"/>
		<xsl:value-of select="result:GetData($Data)"/>
	</xsl:template>
		
test.xml
<Customers>
<data>SudhakarJalli030719751809Bigbenddrmilpitasca95035Rajeevkasarabada032719751788lowerbenddrivesanjoseca94523</data>
</Customers>


Result.xml


<Customers>
	<FirstName>Sudhakar</FirstName>
	<LastName>Jalli</LastName>
	<DOB>03071975</DOB>
	<StreetNum>1809</StreetNum>
	<Street>BigBendDr</Street>
	<City>Milpitas</City>
	<State>CA</State>
	<Zip>95035</Zip>
</Customers>
	<FirstName>Rajeev</FirstName>
	<LastName>Kasarabada</LastName>
	<DOB>03271975</DOB>
	<StreetNum>1788</StreetNum>
	<Street>lowerbenddrive</Street>
	<City>sanjose</City>
	<State>CA</State>
	<Zip>94523</Zip>
</Customers>		

Thanks for your time
Nischal



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.