Subject: Re: [xsl] XSL hold, compare, and replace param value From: "Spencer Tickner" <spencertickner@xxxxxxxxx> Date: Thu, 13 Jul 2006 06:50:03 -0800 |
<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <xsl:apply-templates/> </xsl:template>
<xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template>
<xsl:template match="country[parent::entry/following-sibling::entry]"> <xsl:variable name="nextCountry" select="parent::entry/following-sibling::entry[1]/country"/> <xsl:choose> <xsl:when test="$nextCountry = ."> <country><xsl:apply-templates/></country> </xsl:when> <xsl:otherwise> <country><xsl:value-of select="$nextCountry"/></country> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template match="country[not(parent::entry/following-sibling::entry)]"> <xsl:variable name="nextCountry" select="ancestor::group/following-sibling::group[1]/entry[1]/country"/> <xsl:choose> <xsl:when test="$nextCountry = . or not($nextCountry)"> <country><xsl:apply-templates/></country> </xsl:when> <xsl:otherwise> <country><xsl:value-of select="$nextCountry"/></country> </xsl:otherwise> </xsl:choose> </xsl:template>
Against your XML above, I get Fred's Country Changing as he is the only one who's next country differs,,, Am I reading you correctly?
> I have a problem holding on to a param or variable value in xslt. > Setting it Globally or Locally. > > How can I hold onto the country value? Compare to the next > value, if country is diff. then replace the value for that > param with the next country value?
Please take a step back. Try to describe the problem: what's the input, what's the required output?
It looks to me as if you are trying to code a solution using ideas learned from other programming languages, which might not be the right way to tackle the problem in XSLT.
Michael Kay http://www.saxonica.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSL hold, compare, and re, Michael Kay | Thread | [xsl] XSL hold, compare, and replac, Steve Sze |
RE: [xsl] XSL hold, compare, and re, Michael Kay | Date | [xsl] Recursive wrapping, Khorasani, Houman |
Month |