still having hard time grasping of harder templates great.
right using simple for-each loop sorts , shows data in table. want same thing skip on nodes "state" = "talking out" below current style sheet , below xml. thinking add for-each inside of current loop ignores nodes meet criteria. escaping single quotes since part of larger php script.
<?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="/"> <html> <body> <table cellpadding="3" cellspacing="0" width="390"> <tr> <th style="text-align:left;"><span style="font:20px arial; font-weight:bold;">agent name</span></th> <th style="text-align:center;"><span style="font:20px arial; font-weight:bold;">state</span></th> <th style="text-align:center;"><span style="font:20px arial; font-weight:bold;">time</span></th> </tr> <xsl:for-each select="newdataset/agentsales"> <tr> <xsl:if test="(position() mod 2 = 1)"> <xsl:attribute name="bgcolor">#cccccc</xsl:attribute> </xsl:if> <xsl:if test="agentsales[state=\'talking out\']"> </xsl:if> <td style="text-align:left;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="agentname"/></span></td> <td style="text-align:center;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="state"/></span></td> <td style="text-align:center;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="time"/></span></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
here xml
<?xml version="1.0" encoding="iso-8859-1"?> <newdataset> <agentsales> <agentname>mccallister aaron</agentname> <state>talking out</state> <reason /> <time>9</time> </agentsales> <agentsales> <agentname>appelhans barry</agentname> <state>talking out</state> <reason /> <time>1</time> </agentsales> <agentsales> <agentname>arredondo karla</agentname> <state>talking out</state> <reason /> <time>0</time> </agentsales> <agentsales> <agentname>wooters chad</agentname> <state>talking in</state> <reason /> <time>5</time> </agentsales> <agentsales> <agentname>landini eugene</agentname> <state>not ready</state> <reason>training</reason> <time>16</time> </agentsales> <agentsales> <agentname>brown eyes jonette</agentname> <state>not ready</state> <reason>training</reason> <time>13</time> </agentsales> </newdataset>
while "apply-templates" may seem uncomfortable compared "for-each", perhaps example can show power...
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <body> <table cellpadding="3" cellspacing="0" width="390"> <tr> <th style="text-align:left;"><span style="font:20px arial; font-weight:bold;">agent name</span></th> <th style="text-align:center;"><span style="font:20px arial; font-weight:bold;">state</span></th> <th style="text-align:center;"><span style="font:20px arial; font-weight:bold;">time</span></th> </tr> <xsl:apply-templates select="newdataset/agentsales[state!='talking out']"/> </table> </body> </html> </xsl:template> <xsl:template match="agentsales"> <tr> <xsl:if test="(position() mod 2 = 1)"> <xsl:attribute name="bgcolor">#cccccc</xsl:attribute> </xsl:if> <td style="text-align:left;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="agentname"/></span></td> <td style="text-align:center;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="state"/></span></td> <td style="text-align:center;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="time"/></span></td> </tr> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment