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 February 23rd, 2009, 01:07 AM
Registered User
 
Join Date: Feb 2009
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Question XSLT 1.0 Split one Field into Two

Hi all,

I have a situation where I need to take a XML response and split the values given into two fields. Im using XSLT version 1.0 and my XML looks like this:

<ns:response>
<thisisresponse>abcdef|123456</thisisresponse>
</ns:response>

I would like this to look something like this after XSL transformation:

<field1>abcdef</field1>
<field2>123456</field2>

The separator is the "|"

Is there are simple way to do this?

Last edited by stlyz3; February 23rd, 2009 at 01:22 AM..
 
Old February 23rd, 2009, 02:08 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Try this:

Code:
 
<xsl:template match="ns:response">
<field1><xsl:value-of select="substring-before(., '|')"/></field1>
<field2><xsl:value-of select="substring-after(., '|')"/></field2>
</xsl:template>
__________________
Rummy
 
Old February 23rd, 2009, 02:10 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:ns="http://www.foo.org">
    <xsl:template match="/">
        <field1>
            <xsl:value-of select="substring-before(ns:response/thisisresponse,'|') "/>
        </field1>
        <field2>
            <xsl:value-of select="substring-after(ns:response/thisisresponse,'|') "/>
        </field2>
    </xsl:template>
</xsl:stylesheet>
Cheers, John Bampton
The Following User Says Thank You to JohnBampton For This Useful Post:
stlyz3 (February 23rd, 2009)
 
Old February 23rd, 2009, 03:42 PM
Registered User
 
Join Date: Feb 2009
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks a lot for your help. It worked perfectly!





Similar Threads
Thread Thread Starter Forum Replies Last Post
To Split or Not to Split darrenb Access 2 February 8th, 2008 12:28 PM
XSLT For Each - Field Names lahatfield XSLT 6 May 15th, 2007 06:33 AM
How to split a field into two fields fdtoo SQL Server 2000 0 April 11th, 2006 08:41 PM
Split field at designated character but at " " neo_jakey Classic ASP Professional 0 March 14th, 2005 11:31 AM
split crmpicco Classic ASP Basics 2 February 14th, 2005 08:48 AM





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