This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XSLT parsing XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT parsing XML" Watch "XSLT parsing XML" New topic

XSLT parsing XML

Sriram Vaidhyanathan

Joined: Aug 07, 2001
Posts: 1
I have a question about parsing some XML data using
XSLT, and then using this data in a call to an ASP
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?
Mapraputa Is
Leverager of our synergies

Joined: Aug 26, 2000
Posts: 10065
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=''>
<xsl:template match="names">
<xsl:call-template name="split">
<xsl:with-param name="nameList" select="."/>
<xsl:template name="split">
<xsl:param name="nameList"/>
<xsl:if test="$nameList">
<xsl:variable name="first" select="normalize-space (substring-before ($nameList, ','))"/>
<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, ',')"/>
GetInfo.asp?=<xsl:value-of select="normalize-space ($nameList)"/>

[This message has been edited by Mapraputa Is (edited August 07, 2001).]

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
I agree. Here's the link:
subject: XSLT parsing XML
It's not a secret anymore!