xsl-list
[Top] [All Lists]

Node Position() always equals 1

2005-02-01 09:43:32
Good day, all! :)

The complete XML and XSL are at the bottom of this email. The problem that I'm 
having is that for some reason the spec_off/offer nodes are always returning 
position() = 1... Which means that my numbering is always off because I'm 
basing the numbering on position() + 1... Can anyone explain this?

I tried the transform on three different parsing engines just to make sure that 
I wasn't crazy (which may still be true)... Any help is greatly appreciated...

Thanks!

Cynthia

XML:

<?xml version="1.0" encoding="UTF-8" ?>
<template>
    <versions>
                <version id="CO" gis="true">
                    <name>Corporate</name>
                    <url>http://REPLACE</url>
                    <sLine>Corporate Subject Line</sLine>
                </version>
                <version id="FR" gis="">
                    <name>Franchise</name>
                    <url></url>
                    <sLine>Franchise Subject Line</sLine>
                </version>
    </versions>
<welcome_msg>
    <smi>Welcome to your premiere edition of <i>What's 
New(_at_)BLOCKBUSTER<regTrade /></i>! You'll love our unique mix of the hottest 
new releases and special offers.<br /><br /><i>What's New(_at_)BLOCKBUSTER</i> 
is full of great entertainment options to help you get more from your 
BLOCKBUSTER<regTrade /> membership.</smi>
    <rp>Welcome back to <i>What's New(_at_)BLOCKBUSTER<regTrade /></i>. Your 
e-mail address has been updated through the e-mail change of address process 
you registered for with ReturnPath. We're glad you're receiving <i>What's 
New(_at_)BLOCKBUSTER</i> again!</rp>
</welcome_msg>
<spec_off>
    <offer CO='true' FR='' no_move="false">
        <toc_item name="Promo 1 CO" href="promo1" specOff="true" CO="true" 
FR="" no_move="false" />
        <title>Promo 1 CO</title>
        <copy>Copy for promo 1 for CO.<br /><br />Copy of second 
paragraph.</copy>
        <img imgW="0" imgH="0" href="" align="right" vspace="" 
hspace="">http://a948.g.akamai.net/f/948/166/1h/blockbuster.qrs1.net/ME/images/</img>
 
        <alt></alt>
        <terms show="true">
            <href value="http://REPLACE";>Click here</href> for terms &amp; 
conditions.
        </terms>
        <more show="false">
            <href value="">Click here</href> for more information.
        </more>
        <legal>Legal for promo 1 for CO.</legal>
    </offer>
    <offer CO='true' FR='' no_move="false">
        <toc_item name="Promo 2 CO" href="promo2" specOff="true" CO="true" 
FR="" no_move="false" />
        <title>Promo 2 CO</title>
        <copy>Copy for Promo 2 for CO.</copy>
        <img imgW="0" imgH="0" href="" align="right" vspace="" 
hspace="">http://a948.g.akamai.net/f/948/166/1h/blockbuster.qrs1.net/ME/images/</img>
 
        <alt></alt>
        <terms show="true">
            <href value="http://REPLACE";>Click here</href> for terms &amp; 
conditions.
        </terms>
        <more show="false">
            <href value="">Click here</href> for more information.
        </more>
        <legal>Legal for Promo 2 for CO.</legal>
    </offer>
    <offer CO='' FR='true' no_move="true">
        <toc_item name="Promo 1 FR" href="promo3" specOff="true" CO="" 
FR="true" no_move="true" />
        <title>Promo 1 FR</title>
        <copy>Copy for promo 1 for FR.</copy>
        <img imgW="0" imgH="0" href="" align="right" vspace="" 
hspace="">http://a948.g.akamai.net/f/948/166/1h/blockbuster.qrs1.net/ME/images/</img>
 
        <alt></alt>
        <terms show="false">
            <href value="">Click here</href> for terms &amp; conditions.
        </terms>
        <more show="false">
            <href value="">Click here</href> for more information.
        </more>
        <legal></legal>
    </offer>
    <offer CO='true' FR='' no_move="false">
        <toc_item name="Promo 3 CO" href="promo4" specOff="true" CO="true" 
FR="" no_move="false" />
        <title>Promo 3 Co</title>
        <copy>Copy for Promo 3 for CO.</copy>
        <img imgW="0" imgH="0" href="" align="right" vspace="" 
hspace="">http://a948.g.akamai.net/f/948/166/1h/blockbuster.qrs1.net/ME/images/</img>
 
        <alt></alt>
        <terms show="false">
            <href value="">Click here</href> for terms &amp; conditions.
        </terms>
        <more show="false">
            <href value="">Click here</href> for more information.
        </more>
        <legal></legal>
    </offer>
</spec_off>
</template>

XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:variable name="version">CO</xsl:variable>
<xsl:variable name="welcome_msg">none</xsl:variable>
<xsl:variable name="count"><xsl:value-of 
select="count(template/spec_off/offer[./@*[local-name()=$version]='true'])" 
/></xsl:variable>
<xsl:variable name="maxLength" select="72" />
<xsl:variable name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
 <xsl:output method="html" indent="no" encoding="UTF-8" />
<xsl:template match="/">
<font size="2" face="courier">
<xsl:if test="template/spec_off/offer">
<xsl:choose>
    <xsl:when test="$welcome_msg != 'none' and 
template/welcome_msg/node()[name(.) = $welcome_msg] != ''">
        <xsl:apply-templates 
select="template/spec_off/offer[./@*[local-name()=$version]='true']" />
    </xsl:when>
    <xsl:otherwise>
        <xsl:if test="$count > 1">
            <xsl:apply-templates 
select="template/spec_off/offer[./@*[local-name()=$version]='true'][position() 
&gt; 1]" />
        </xsl:if>
    </xsl:otherwise>
</xsl:choose>
</xsl:if>
</font>
</xsl:template>
<xsl:template match="offer">
    <xsl:for-each select=".">
<xsl:if test="./@no_move != 'true'">
----------------------------------------------------------------------<br />
<xsl:call-template name="breakLength"><xsl:with-param name="copy"><xsl:value-of 
select="position()+1" />. <xsl:apply-templates select="./title" 
/></xsl:with-param><xsl:with-param name="maxLength" select="$maxLength" 
/></xsl:call-template>
<br />
<xsl:call-template name="breakLength">
<xsl:with-param name="copy"><xsl:apply-templates select="./copy" 
/></xsl:with-param>
<xsl:with-param name="maxLength" select="$maxLength" />
</xsl:call-template>
<br />
<xsl:if test="./more/@show='true'">
<xsl:call-template name="replaceHere"><xsl:with-param 
name="toReplace"><xsl:copy-of select="./more" 
/></xsl:with-param></xsl:call-template>
<br />
<xsl:value-of select="./more/href/@value" /><br />
</xsl:if>
<xsl:if test="./terms/@show = 'true'">
<xsl:call-template name="replaceHere"><xsl:with-param 
name="toReplace"><xsl:copy-of select="./terms" 
/></xsl:with-param></xsl:call-template>
<br />
<xsl:value-of select="./terms/href/@value" /><br />
</xsl:if>
<xsl:if test="./terms/@show='true' or ./more/@show='true'"><br /></xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="breakLength">
<xsl:param name="maxLength" />
<xsl:param name="copy" />
<xsl:param name="current" />
<xsl:choose>
<xsl:when test="$copy">
<xsl:variable name="nextWord">
<xsl:choose>
<xsl:when test="contains($copy,' ')">
<xsl:value-of select="substring-before($copy,' ')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$copy" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="string-length($current)+1+string-length($nextWord) &lt; 
$maxLength">
<xsl:call-template name="breakLength">
<xsl:with-param name="maxLength" select="$maxLength" />
<xsl:with-param name="copy" select="substring-after($copy,' ')" />
<xsl:with-param name="current">
<xsl:choose>
<xsl:when test="$current!=''"><xsl:value-of select="concat($current,' 
',$nextWord)" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$nextWord" /></xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$current" />
<br />
<xsl:call-template name="breakLength">
<xsl:with-param name="maxLength" select="$maxLength" />
<xsl:with-param name="copy" select="$copy" />
<xsl:with-param name="current" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$current" />
<br />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="replaceHere">
<xsl:param name="toReplace" />
<xsl:copy-of select="substring-before($toReplace,'here')" />below<xsl:copy-of 
select="substring-after($toReplace,'here')" />
</xsl:template>
</xsl:stylesheet>


PS - I included several extra templates so that you could see all 
transformations that are happening in case I've done something else wrong. 
Also, if you want to change the variables to see different output, "version" 
will be either "CO" or "FR" and "welcome_msg" will be either "none", "smi" or 
"rp". Thanks!

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>