File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT parsing XML" Watch "XSLT parsing XML" New topic
Author

XSLT parsing XML

Sriram Vaidhyanathan
Greenhorn

Joined: Aug 07, 2001
Posts: 1
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
Mapraputa Is
Leverager of our synergies
Sheriff

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='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>
<xsltherwise>
GetInfo.asp?=<xsl:value-of select="normalize-space ($nameList)"/>
</xsltherwise>
</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).]


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: http://aspose.com/file-tools
 
subject: XSLT parsing XML