 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 4th, 2006, 10:59 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
missing attribute
Hi, New to the forum so apologies if this has been answered before but I cannot find it anywhere.
I have the following XML (golfers), as you can see, only the tie has a HADVALUE (home/away/draw value).
Code:
<market DMLTYPE="U" NAME="21.20 W.Short Jr/L.Glover" >
<selection DMLTYPE="U" NAME="Tie" HADVALUE="D" />
<selection DMLTYPE="U" NAME="Short Jr, Wes" />
<selection DMLTYPE="U" NAME="Glover, Lucas" />
</market>
So my existing stylesheet uses the following:
Code:
<xsl:with-param name="thisRunnerStatus"><xsl:value-of select="selection[@HADVALUE='H']/@IDSELECTIONSTATE"/></xsl:with-param>
<xsl:with-param name="otherRunnerStatus"><xsl:value-of select="selection[@HADVALUE='A']/@IDSELECTIONSTATE"/></xsl:with-param>
How do I access these individual selections now they do not have a HADVALUE !?
Please help and I'll buy you a pint (or a glass of wine for the ladies).
|
|

January 4th, 2006, 11:21 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I'm afraid it's not clear enough what you're trying to do.
You've posted a fragment of code:
<xsl:with-param name="thisRunnerStatus"><xsl:value-of select="selection[@HADVALUE='H']/@IDSELECTIONSTATE"/></xsl:with-param>
(1) in your source document the "selection" element doesn't have an attribute called IDSELECTIONSTATE, so this will select nothing
(2) An xsl:variable/param/with-param containing a single xsl:value-of is nearly always wrong. Write
<xsl:with-param name="thisRunnerStatus" select="selection[@HADVALUE='H']/@IDSELECTIONSTATE"/>
The difference is that this selects the value without the overhead of copying it and constructing a new tree structure. Also, it's less typing!
But I can't help you with your original problem.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

January 4th, 2006, 12:13 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks for your comments Michael, apologies for my quick posting.
Basically, ignore my bad code (its actually someone elses template).
The problem I have is this bit:
<xsl:with-param name="thisRunnerStatus" select="selection [@HADVALUE='H']/@NAME"/>
as this attribute (bolded in the example) only exists in one selection, not all 3.
How do I parse all 3 selections into table cells for example !?
Cheers for your help
|
|

January 4th, 2006, 12:54 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>ignore my bad code
You want a magician: someone who silently corrects the errors you knew about and then tells you about the ones that you didn't know about!
I don't understand your problem. You've chosen to apply the predicate [@HADVALUE='H'] to select those "selection" elements that have this attribute. If you want to select those that don't have this attribute, then don't apply the predicate. To explicitly select elements that don't have a HADVALUE attribute, use selection[not(@HADVALUE)].
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

January 4th, 2006, 01:08 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Apologies Michael.
My full XML file is here:
<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet href = 'bf_golf2ball.xsl' type = 'text/xsl' ?>
<page timestamp="632719617063359371" id="146998_10" type="master" date="2006-01-05" version="1.0.0" sporttype="Golf" sportname="Golf" mnem="MS" daylightsaving="False" localtime="05/01/2006 21:30:00" utc="05/01/2006 21:30:00" utcoffsetmins="0">
<event DMLTYPE="U" TABLEID="75885.10" TEMPLATELIST="golf#" SPORTTYPE="Golf" SPORT="Golf" IDFOEVENT="75885.10" NAME="Mercedes Champ - 1st Rd 2-Balls" FULLNAME="Mercedes Championship - 1st Rd 2-Balls" IDFOBOLIFESTATE="O" ISHANDICAPRACE="0">
<market DMLTYPE="U" TABLEID="146998.10" TEMPLATELIST="golf#" IDFOEVENT="75885.10" IDFOMARKET="146998.10" NAME="21.30 R.Gamez/K.J Choi" FULLNAME="21.30 R.Gamez/K.J Choi" IDFOBOLIFESTATE="O" ISTRADABLE="-1" CURRENTEWREDUCTION="1" CURRENTEWPLACETERMS="1" IDFODRAWOUTCOMETYPE="TIE" IDFOHADTYPE="HAD" IS4INRUNNING="0" ISGPOFFERON="0" ISHEAD2HEAD="-1" ISMATCHHANDICAPTYPE="0" IDFOSELECTIONTYPE="PARTICIPANT" IDFOPARTICIPANTTYPE="PLAYER" ISTRAPBETTINGOPTIONON="0" ISPLACEONLYOPTIONON="0" TSBOLIFESTATE="04/01/2006 08:21:30" TSISTRADABLE="04/01/2006 08:21:30" IDFOSELECTIONORDER="SETUP" PRICETYPES="CP" ISASIANHANDICAP="0" TSBETEND="05/01/2006 21:30:00" IDFOEWOFFERTYPE="NONE" TSOFF="05/01/2006 21:30:00">
<selection DMLTYPE="U" TABLEID="3588978.10" IDFOSELECTION="3588978.10" IDFOMARKET="146998.10" NAME="Tie" FULLNAME="Tie" IDFOBOLIFESTATE="N" IDSELECTIONSTATE="N" SHORTNAME="Tie" ALTERNATIVENAME="Tie" ISGPOPTIONON="0" ISRESERVE="0" HADVALUE="D" INTERNALORDER="3588978.10" CURRENTPRICEUP="2" CURRENTPRICEDOWN="1" DECIMALPRICE="9.00" PRICEHISTORY="8/1" />
<selection DMLTYPE="U" TABLEID="3588994.10" IDFOSELECTION="3588994.10" IDFOMARKET="146998.10" IDFOPARTICIPANT="997448.10" NAME="Gamez, Robert" FULLNAME="Gamez, Robert" IDFOBOLIFESTATE="N" IDSELECTIONSTATE="N" SHORTNAME="GAMEZ, RO" ALTERNATIVENAME="GAMEZ, RO" ISGPOPTIONON="0" ISRESERVE="0" INTERNALORDER="3588994.10" CURRENTPRICEUP="3" CURRENTPRICEDOWN="1" DECIMALPRICE="2.63" PRICEHISTORY="13/8" />
<selection DMLTYPE="U" TABLEID="3588995.10" IDFOSELECTION="3588995.10" IDFOMARKET="146998.10" IDFOPARTICIPANT="997902.10" NAME="Choi, K J" FULLNAME="Choi, K J" IDFOBOLIFESTATE="N" IDSELECTIONSTATE="N" SHORTNAME="CHOI, K J" ALTERNATIVENAME="CHOI, K J" ISGPOPTIONON="0" ISRESERVE="0" INTERNALORDER="3588995.10" CURRENTPRICEUP="4" CURRENTPRICEDOWN="1" DECIMALPRICE="1.62" PRICEHISTORY="8/13" />
</market>
</event>
<event DMLTYPE="U" TABLEID="75885.10" TEMPLATELIST="golf#" SPORTTYPE="Golf" SPORT="Golf" IDFOEVENT="75885.10" NAME="Mercedes Champ - 1st Rd 2-Balls" FULLNAME="Mercedes Championship - 1st Rd 2-Balls" IDFOBOLIFESTATE="O" ISHANDICAPRACE="0">
<market DMLTYPE="U" TABLEID="146997.10" TEMPLATELIST="golf#" IDFOEVENT="75885.10" IDFOMARKET="146997.10" NAME="21.20 W.Short Jr/L.Glover" FULLNAME="21.20 W.Short Jr/L.Glover" IDFOBOLIFESTATE="O" ISTRADABLE="-1" CURRENTEWREDUCTION="1" CURRENTEWPLACETERMS="1" IDFODRAWOUTCOMETYPE="TIE" IDFOHADTYPE="HAD" IS4INRUNNING="0" ISGPOFFERON="0" ISHEAD2HEAD="-1" ISMATCHHANDICAPTYPE="0" IDFOSELECTIONTYPE="PARTICIPANT" IDFOPARTICIPANTTYPE="PLAYER" ISTRAPBETTINGOPTIONON="0" ISPLACEONLYOPTIONON="0" TSBOLIFESTATE="04/01/2006 08:21:30" TSISTRADABLE="04/01/2006 08:21:30" IDFOSELECTIONORDER="SETUP" PRICETYPES="CP" ISASIANHANDICAP="0" TSBETEND="05/01/2006 21:20:00" IDFOEWOFFERTYPE="NONE" TSOFF="05/01/2006 21:20:00">
<selection DMLTYPE="U" TABLEID="3588977.10" IDFOSELECTION="3588977.10" IDFOMARKET="146997.10" NAME="Tie" FULLNAME="Tie" IDFOBOLIFESTATE="N" IDSELECTIONSTATE="N" SHORTNAME="Tie" ALTERNATIVENAME="Tie" ISGPOPTIONON="0" ISRESERVE="0" HADVALUE="D" INTERNALORDER="3588977.10" CURRENTPRICEUP="5" CURRENTPRICEDOWN="1" DECIMALPRICE="9.00" PRICEHISTORY="8/1" />
<selection DMLTYPE="U" TABLEID="3588992.10" IDFOSELECTION="3588992.10" IDFOMARKET="146997.10" IDFOPARTICIPANT="1212518.10" NAME="Short Jr, Wes" FULLNAME="Short Jr, Wes" IDFOBOLIFESTATE="N" IDSELECTIONSTATE="N" SHORTNAME="Short Jr" ALTERNATIVENAME="Short Jr" ISGPOPTIONON="0" ISRESERVE="0" INTERNALORDER="3588992.10" CURRENTPRICEUP="6" CURRENTPRICEDOWN="1" DECIMALPRICE="2.38" PRICEHISTORY="11/8" />
<selection DMLTYPE="U" TABLEID="3588993.10" IDFOSELECTION="3588993.10" IDFOMARKET="146997.10" IDFOPARTICIPANT="997823.10" NAME="Glover, Lucas" FULLNAME="Glover, Lucas" IDFOBOLIFESTATE="N" IDSELECTIONSTATE="N" SHORTNAME="GLOVER, L" ALTERNATIVENAME="GLOVER, L" ISGPOPTIONON="0" ISRESERVE="0" INTERNALORDER="3588993.10" CURRENTPRICEUP="7" CURRENTPRICEDOWN="1" DECIMALPRICE="1.73" PRICEHISTORY="8/11" />
</market>
</event>
</page>
and my code states:
<xsl:for-each select="page/event/market">
<xsl:sort select="selection/@IDSELECTIONSTATE ='NR'" order="ascending"/>
<xsl:sort select="@TSBETEND !=''" order="descending"/>
<xsl:sort select="@TSBETEND" order="ascending"/>
<xsl:if test ="position() <=($PageNum * $NumOnPage) and position() >=(($PageNum * $NumOnPage) -($NumOnPage - 1))">
<xsl:choose>
<xsl:when test="@ISTRADABLE='0' or @IDFOBOLIFESTATE='C' or (@ISTRADABLE='-1' and @IDFOBOLIFESTATE='R')"/>
<xsl:otherwise>
<tr>
<xsl:attribute name="height"><xsl:value-of select="518 div $NumOnPage"/></xsl:attribute>
<td align="right" class="ODDS24">
<xsl:call-template name="doOdds">
<xsl:with-param name="upPrice"><xsl:value-of select="selection[not(@HADVALUE)]/@CURRENTPRICEUP"/></xsl:with-param>
<xsl:with-param name="downPrice"><xsl:value-of select="selection[not(@HADVALUE)]/@CURRENTPRICEDOWN"/></xsl:with-param>
<xsl:with-param name="thisRunnerStatus"><xsl:value-of select="selection[not(@HADVALUE)]/@IDSELECTIONSTATE"/></xsl:with-param>
<xsl:with-param name="otherRunnerStatus"><xsl:value-of select="selection[not(@HADVALUE)]/@IDSELECTIONSTATE"/></xsl:with-param>
<xsl:with-param name="checkClosed">
<xsl:if test="@IDFOBOLIFESTATE='O' and @ISTRADABLE='0'">TRUE</xsl:if>
<xsl:if test="@IDFOBOLIFESTATE='C' and @ISTRADABLE='-1'">TRUE</xsl:if>
</xsl:with-param>
</xsl:call-template>
</td>
<td class="SELECTION24">
<nobr>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:call-template name="doInitial"><xsl:with-param name="att" select="selection[not(@HADVALUE)]/@NAME"/><xsl:with-param name="len" select="10"/></xsl:call-template>
</nobr>
</td>
<td align="center" class="SUBHEADING">V</td>
<td class="SELECTION24">
<nobr>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:call-template name="doInitial"><xsl:with-param name="att" select="selection[not(@HADVALUE)]/@NAME"/><xsl:with-param name="len" select="10"/></xsl:call-template>
</nobr>
</td>
<td align="right" class="ODDS24">
<xsl:call-template name="doOdds">
<xsl:with-param name="upPrice"><xsl:value-of select="selection[not(@HADVALUE)]/@CURRENTPRICEUP"/></xsl:with-param>
<xsl:with-param name="downPrice"><xsl:value-of select="selection[not(@HADVALUE)]/@CURRENTPRICEDOWN"/></xsl:with-param>
<xsl:with-param name="thisRunnerStatus"><xsl:value-of select="selection[not(@HADVALUE)]/@IDSELECTIONSTATE"/></xsl:with-param>
<xsl:with-param name="otherRunnerStatus"><xsl:value-of select="selection[@HADVALUE='H']/@IDSELECTIONSTATE"/></xsl:with-param>
<xsl:with-param name="checkClosed">
<xsl:if test="@IDFOBOLIFESTATE='O' and @ISTRADABLE='0'">TRUE</xsl:if>
<xsl:if test="@IDFOBOLIFESTATE='C' and @ISTRADABLE='-1'">TRUE</xsl:if>
</xsl:with-param>
</xsl:call-template>
</td>
<td class="OFFTIME24"><xsl:value-of select="substring(@TSBETEND, 12, 5)"/></td>
<!--td class="OFFTIME"><nobr><xsl:text disable-output-escaping="yes">&nbsp;</xsl:text> TIE<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<span class="SUBHEADING"><xsl:value-of select="selection[@HADVALUE='D']/@CURRENTPRICEUP"/><xsl:if test="selection[@HADVALUE='D']/@CURRENTPRICEDOWN != ''">/</xsl:if><xsl:value-of select="selection[@HADVALUE='D']/@CURRENTPRICEDOWN"/><xsl:text disable-output-escaping="yes">&nbsp;</xsl:text></span></nobr></td-->
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
As can be seen, the output is
6/1 short jr, w v short jr, w 6/1
3/1 gamez,r v gamez, r 3/1
its putting the home players against the home players, choosing the first selection thats not a draw.
The problem is, there is no HAD value for the home and the away selections yet there is for the tie (tie = draw).
Hope this makes more sense.
|
|

January 4th, 2006, 01:15 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have your book in front of me Michael, I've just figured out who you are.
Cheers
|
|

January 4th, 2006, 01:20 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I don't know if I'm making myself clear though, let me try pseudo code.
I have three values in an array
selection[]=(Home, Draw, Away)
If I wanted to select away, I would use
selection[2]
but if I have three XML nodes:
<market>
<selection name="home" />
<selection name="draw" />
<selection name="away" />
</market>
How do I get at individual nodes, some kind of pointer?
I think I'm confusing myself now.
|
|

January 4th, 2006, 01:57 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have found a solution, might not be the best solution out there but it seems to work for my needs.
Code:
<xsl:with-param name="att" select="selection[position()=3]/@NAME"/><xsl:with-param name="len" select="10"/></xsl:call-template>
seems to work, the bolded part is my addition and lets me select the node.
Thanks for your help (and patience) Mike.
|
|

January 4th, 2006, 02:12 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
<market>
<selection name="home" />
<selection name="draw" />
<selection name="away" />
</market>
How do I get at individual nodes, some kind of pointer?
You can refer to them as
selection[@name='home']
selection[@name='draw']
selection[@name='away']
or if you prefer, as
selection[1], selection[2], and selection[3]
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
 |