• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

XSLT parsing XML

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have a question about parsing some XML data using
XSLT, and then using this data in a call to an ASP
file.
The XML is of the format:
<names> Sriram, John, Brad, Bill </names>
And I'd like to be able to write XSLT to somehow parse
this data into separate strings and perform the calls
GetInfo.asp?=Sriram, GetInfo.asp?=Brad, etc. one by
one in order in a looplike structure.
Could you be able to help out on this?
Thanks,
Sriram
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here the trick is to put splitting code in a template and to call it recursively.
<?xml version='1.0'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="names">
<xsl:call-template name="split">
<xsl:with-param name="nameList" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="split">
<xsl:param name="nameList"/>
<xsl:if test="$nameList">
<xsl:variable name="first" select="normalize-space (substring-before ($nameList, ','))"/>
<xsl:choose>
<xsl:when test="$first">
GetInfo.asp?=<xsl:value-of select="$first"/>
<xsl:call-template name="split">
<xsl:with-param name="nameList" select="substring-after ($nameList, ',')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
GetInfo.asp?=<xsl:value-of select="normalize-space ($nameList)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Output:
GetInfo.asp?=Sriram
GetInfo.asp?=John
GetInfo.asp?=Brad
GetInfo.asp?=Bill

[This message has been edited by Mapraputa Is (edited August 07, 2001).]
 
You didn't tell me he was so big. Unlike this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic