This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: string question


Another great idea, but I'd be writing to many modes. For all who are
intrigued, I used Michael's algorithm with a tiny bit of tweaking (acutally
error correction):

<xsl:template match="b310">
	<xsl:variable name="priority"
				  select="concat(
					    normalize-space(
					    translate(., '/_:;,~', '       ')), ' ')" />
	<xsl:call-template name="do-segments">
  		<xsl:with-param name="token" select="$priority"/>
  	</xsl:call-template>
</xsl:template>

<xsl:template name="do-segments">
	<xsl:param name="token"/>
	<xsl:if test="$token">
		<xsl:value-of select="concat(' PR_', substring-before($token,' '), ' ')"/>
		<xsl:call-template name="do-segments">
			<xsl:with-param name="token" select="substring-after($token,' ')"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>


: How about this.
:
: The XML
: -------------------------------
:    <test>
:       <b310>08/773,384</b310>
:       <b310>090/77332,38476</b310>
:       <b310>08890/77387262,384768278392</b310>
:    </test>
: =============================
: The XSL
: --------------------------
: <?xml version="1.0" encoding="ISO-8859-1"?>
: <xsl:stylesheet version="1.0"
:                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
:
: <xsl:template match="test">
:    <xsl:apply-templates select="b310" mode="first"/>
: </xsl:template>
:
: <xsl:template match="b310" mode="first">
:    PR_<xsl:value-of select="substring-before(., '/')" />
:    <xsl:apply-templates select="." mode="second"/>
: </xsl:template>
:
: <xsl:template match="b310" mode="second">
:    PR_<xsl:value-of select="substring-before(substring-after(.,
: '/'), ',')"
: />
:    <xsl:apply-templates select="." mode="third"/>
: </xsl:template>
:
: <xsl:template match="b310" mode="third">
:    PR_<xsl:value-of select="substring-after(substring-after(., '/'), ',')"
: />
:    <br/>
: </xsl:template>
: </xsl:stylesheet>
: ============================
: The output:
: ------------------------------------
:    PR_08
:    PR_773
:    PR_384<br/>
:    PR_090
:    PR_77332
:    PR_38476<br/>
:    PR_08890
:    PR_77387262
:    PR_384768278392<br/>
:
:
:
:
: ----- Original Message -----
: From: "David Santamauro" <david.santamauro@snet.net>
: To: "Jeni Tennison" <mail@jenitennison.com>
: Cc: "Xsl-List" <xsl-list@lists.mulberrytech.com>
: Sent: Wednesday, February 21, 2001 10:35 PM
: Subject: RE: [xsl] string question
:
:
: > thanks for the clues... unfortunately, everything is variable
: (length and
: > punctuation).
: >
: > I'll try your and Michael's solution and report back on the
: progess. Once
: > again, thanks.
: >
: > David
: >
: > -----Original Message-----
: > From: Jeni Tennison [mailto:mail@jenitennison.com]
: > Sent: Wednesday, February 21, 2001 08:10
: > To: David Santamauro
: > Cc: Xsl-List
: > Subject: Re: [xsl] string question
: >
: >
: > Hi David,
: >
: > >>From this xml (those IP persons might recognize this):
: > > <b310>08/773,384</b310>
: > >
: > > I need:
: > > PR_08/773,384 PR_08 PR_773 PR_384
: > >
: > > Basically, all punctuation (and spaces) are "segment" delimiters.
: Starting
: > > with entire content, each segment is then prefixed with PR_. Any help
: > would
: > > be greatly appreciated.
: >
: > Assuming that your strings are always of the form:
: >
: >   DD/DDD,DDD
: >
: > (where D is a digit) you could use:
: >
: > PR_<xsl:value-of select="b310" />
: > PR_<xsl:value-of select="substring(b310, 1, 2)" />
: > PR_<xsl:value-of select="substring(b310, 4, 3)" />
: > PR_<xsl:value-of select="substring(b310, 8, 3)" />
: >
: > If the lengths of the different parts of the strings can vary, then
: > you need to use substring-before() and substring-after():
: >
: > PR_<xsl:value-of select="b310" />
: > PR_<xsl:value-of select="substring-before(b310, '/')" />
: > PR_<xsl:value-of select="substring-before(
: >                            substring-after(b310, '/'), ',')" />
: > PR_<xsl:value-of select="substring-after(
: >                            substring-after(b310, '/'), ',')" />
: >
: > If there can be more parts to the string, then you need a recursive
: > solution.  If that's the case, then can you write a general pattern
: > for the string, and we'll try to work something out?
: >
: > I hope that helps,
: >
: > Jeni
: >
: > ---
: > Jeni Tennison
: > http://www.jenitennison.com/
: >
: >
: >
: >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
: >
:
:
:  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
:


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]