|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Second try: Search and replace many strings that m
Ok, just for fun :) here is a stylesheet that doesnt need the javascript
to find out if its the first occurance of the name.
It does this by taking each text() node and getting the
substring-before() of all the text() nodes in the entire xml doc (no,
really :)
It then tests to see if this substring contains the name that is
currently being worked on, if it doesnt (ie this is the first occurance)
then it outputs the <span> (which I havent got around to changing to the
link...) otherwise it outputs the plain text().
If two names occur in one text() node when one has occured before and
one hasnt then of course they will both 'fail'... there is no way around
this.
If you really want to do this properly (and much more simply), then you
will need to do two passes.
have fun :)
cheers
andrew
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
version="1.0">
<xsl:variable name="quotes-rtf">
<xsl:for-each select="//quote">
<quote who="{@who}"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="quotes" select="msxsl:node-set($quotes-rtf)"/>
<xsl:variable name="theRoot" select="/"/>
<xsl:variable name="everything" select="$theRoot//text()"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="checkIfFirst">
<xsl:param name="theText" select="nothing"/>
<xsl:param name="who" select="noone"/>
<xsl:variable name="precedingText"
select="substring-before($theRoot,$theText)"/>
<xsl:choose>
<xsl:when test="contains($precedingText,$who)">
<xsl:value-of select="$theText"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($theText,$who)"/>
<quoteLink><xsl:value-of select="$who"/></quoteLink>
<xsl:value-of select="substring-after($theText,$who)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkForName">
<xsl:param name="theText" select="notext"/>
<xsl:param name="position" select="1"/>
<xsl:variable name="who" select="$quotes/quote[$position]/@who"/>
<xsl:choose>
<xsl:when test="count($quotes/quote) >= $position">
<xsl:choose>
<xsl:when test="contains($theText,$who)">
<xsl:call-template name="checkIfFirst">
<xsl:with-param name="theText" select="$theText"/>
<xsl:with-param name="who" select="$who"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkForName">
<xsl:with-param name="theText" select="$theText"/>
<xsl:with-param name="position" select="$position + 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()">
<xsl:variable name="theText" select="."/>
<xsl:call-template name="checkForName">
<xsl:with-param name="theText" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template match="section">
<xsl:apply-templates select="text()"/>
</xsl:template>
</xsl:stylesheet>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
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
|

Cart








