473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XSL : spliting string in an un identified number of sub-strings

Hello,
I'm transforming a XML document in XHTML but I have problems using
sub-strings, it will be clearer with an exemple:

What I have:
<form href="identification.php?PHPSESSID=134134&page=2&p aram=3" >
</form>
what I want:
<form action="identification.php" >
<input name="PHPSESSID" value="134134"/>
<input name="page" value="2"/>
<input name="param" value="3"/>
</form>

My main problem is I don't know how many parameters will
identification.php have. I should use <xsl: for-each> but how can I
split a string in an non-known number of substrings?

Any help would be appreciated.

PS: I'm using Sablotron with PHP

Sebek - Sebek <at/> caramail <dot/> com
Jul 20 '05 #1
2 4327

"Sebek" <se***@caramail.com> wrote in message
news:50**************************@posting.google.c om...
Hello,
I'm transforming a XML document in XHTML but I have problems using
sub-strings, it will be clearer with an exemple:

What I have:
<form href="identification.php?PHPSESSID=134134&page=2&p aram=3" >
</form>
what I want:
<form action="identification.php" >
<input name="PHPSESSID" value="134134"/>
<input name="page" value="2"/>
<input name="param" value="3"/>
</form>

My main problem is I don't know how many parameters will
identification.php have. I should use <xsl: for-each> but how can I
split a string in an non-known number of substrings?

Any help would be appreciated.

PS: I'm using Sablotron with PHP

Sebek - Sebek <at/> caramail <dot/> com
First of all, please, do note that the source xml document you provided is
not a well-formed xml document. Unescaped ampersand in character data is
illegal in XML. The corrected xml document is:

<form href="identification.php?PHPSESSID=134134&amp;page =2&amp;param=3" >
</form>

The transformation you want is most easily implemented using the
"str-split-to-words" template from FXSL.

This transformation:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ext="http://exslt.org/common"
exclude-result-prefixes="ext"


<xsl:import href="strSplit-to-Words.xsl"/>

<xsl:output indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="/">
<xsl:variable name="vwordParams">
<xsl:call-template name="str-split-to-words">
<xsl:with-param name="pStr" select="/*/@href"/>
<xsl:with-param name="pDelimiters"
select="'&amp;?'"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="vParams"
select="ext:node-set($vwordParams)/*"/>
<form action="{$vParams[1]}">
<xsl:for-each select="$vParams[position()>1]">
<input name="{substring-before(.,'=')}"
value="{substring-after(.,'=')}"/>
</xsl:for-each>
</form>
</xsl:template>
</xsl:stylesheet>

when applied upon the source.xml above, produces the desired result:

<form action="identification.php">
<input name="PHPSESSID" value="134134"/>
<input name="page" value="2"/>
<input name="param" value="3"/>
</form>
Hope this helped.
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Jul 20 '05 #2


Sebek wrote:
I'm transforming a XML document in XHTML but I have problems using
sub-strings, it will be clearer with an exemple:

What I have:
<form href="identification.php?PHPSESSID=134134&page=2&p aram=3" >
</form>
what I want:
<form action="identification.php" >
<input name="PHPSESSID" value="134134"/>
<input name="page" value="2"/>
<input name="param" value="3"/>
</form>

My main problem is I don't know how many parameters will
identification.php have. I should use <xsl: for-each> but how can I
split a string in an non-known number of substrings?

Any help would be appreciated.

PS: I'm using Sablotron with PHP


You can write recursive templates in XSLT which do such processsing,
with the XML input being

<form href="identification.php?PHPSESSID=134134&amp;page =2&amp;param=3">
</form>

and the stylesheet being

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="form">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="@href">
<xsl:variable name="action" select="substring-before(., '?')" />
<xsl:variable name="queryString" select="substring-after(., '?')" />
<xsl:attribute name="action"><xsl:value-of select="$action"
/></xsl:attribute>
<xsl:call-template name="argsToInputs">
<xsl:with-param name="queryString" select="$queryString" />
</xsl:call-template>
</xsl:template>

<xsl:template name="argsToInputs">
<xsl:param name="queryString" />
<xsl:variable name="firstArg">
<xsl:choose>
<xsl:when test="contains($queryString, '&amp;')">
<xsl:value-of select="string(substring-before($queryString,
'&amp;'))" />
</xsl:when>
<xsl:otherwise><xsl:value-of select="string($queryString)"
/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="remainingQueryString"
select="substring-after($queryString, '&amp;')" />
<xsl:if test="$firstArg != ''">
<input name="{substring-before($firstArg, '=')}"
value="{substring-after($firstArg, '=')}" />
<xsl:call-template name="argsToInputs">
<xsl:with-param name="queryString" select="$remainingQueryString" />
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

the output is

<form action="identification.php"><input value="134134"
name="PHPSESSID"/><input value="2" name="page"/><input value="3"
name="param"/>
</form>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Sreejith S S Nair | last post by:
hi there, I have a panel control which contain more than 10 label controls. these label controls are added dynamically by user. In this application user can slit a control into not less than...
0
by: Sreejith S S Nair | last post by:
hi, Setp one. i have one panel control in my form. I am spliting this panel control into two part say working region and holding region. This spliting is only logic spliting. That is i...
5
by: LU | last post by:
VAR1 = 3/4 VAR2 = 2 I user can submit the values "3/4" or "2" (VAR1, VAR2 represent any numbers) when user submits "3/4" we assume 1sthalf/2ndhalf These values are saved into database as a row...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
26
by: alberto | last post by:
Hi. Im newbie in C language. I have a binary file with many character arrays of 50 character defined as char array But in some cases, many of these 50 characters are not being used. I would...
1
by: Nightman | last post by:
Hi How to split an address field up, when the user has entered it in one field with each address line separated by carriage return. I like to have a button, which can be clicked to autofill the...
9
by: keliie | last post by:
Hello (from Access novice), I'm building a switchboard form (using a Treeview object). The treeview is populated by two tables (tblSwitchboardParent and tblSwitchboardChild). Within...
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
1
by: sehguh | last post by:
Hello folks I have recently been studying a book called "sams teach yourself asp.net 2.0 in24 hours by scott mitchell. I have reached page 614 but when i tried to run an asp page called...
1
by: kalia | last post by:
I have a text file and i want to Split the file into mulitple files based off the city and then create new files with the city name. I am able to read the file and also chnaged the semi colon to a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.