[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Can XSLT be used to parse and "break up" a single
Hi > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > John Svazic > Sent: Wednesday, April 23, 2003 3:42 PM > To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx' > Subject: Can XSLT be used to parse and "break up" a > single XML Tag value? > > > Basically what I have is something like the following: > > <field name="links">Project > Page=http://www.mycomp.com/project.htm;Feature > Page=http://www.mycomp.com/feature.htm</field> > > What I want to do is to break up each "section" (delimited with a > semi-colon) and then break up each of these "sections" into > the display name and URL (delimited by the equals sign). Is > there any way to do this in XSLT? TIA. > Try this: <xsl:template match="field"> <xsl:call-template name="tokens"/> </xsl:template> <xsl:template name="tokens"> <xsl:param name="str" select="string(.)"/> <xsl:param name="sep" select="' '"/> <xsl:choose> <xsl:when test="contains($str,';')"> <xsl:call-template name="links"> <xsl:with-param name="str" select="substring-before($str,';')"/> </xsl:call-template> <xsl:value-of select="$sep"/> <xsl:call-template name="tokens"> <xsl:with-param name="str" select="substring-after($str,';')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="links"> <xsl:with-param name="str" select="$str"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="links"> <xsl:param name="str" select="string(.)"/> <xsl:choose> <xsl:when test="contains($str,'=')"> <a href="{substring-after($str,'=')}"><xsl:value-of select="substring-before($str,'=')"/></a> </xsl:when> <xsl:otherwise> <a href="{$str}"><xsl:value-of select="$str"/></a> </xsl:otherwise> </xsl:choose> </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|