Jump to content

IF Statement Problem


FamilyGuy

Recommended Posts

Ok I have my XML doc which look like this

<Row1><Number1>3</Number1><Number2>6</Number2><Number3>4</Number3><Number4>1</Number4><Number5>7</Number5><Number6>8</Number6><Number7 problem="yes">5</Number7><Number8 problem="yes">2</Number8><Number9>9</Number9></Row1>

and my XSlt looks like this

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><head>        <!--The link for the CSS File-->     <link rel="stylesheet" href="stylesheet.css" type="text/css"/>     <title>Soduku Problem</title></head><body>   <table width="100%" height="25%" cellspacing="0">	<tr><td colspan="2"><img src="Titlepic.jpg"/></td> </tr>	<tr><td class="MainHeading" colspan="2">Navigation Menu</td></tr>	<tr><td class="NavBar"><a href="Problem">Problem</a></td><td Class="NavBar"><a href="Solution">Solution</a></td></tr></table><br/><br/><xsl:apply-templates select="Sudoku"/>   </body></html></xsl:template><!--Match template Sudoku, first level of SudokuSolut.xml--><xsl:template match="Sudoku"><table class="main" border="0" cellspacing="0" ><xsl:apply-templates select="Row1"/>    <xsl:apply-templates select="Row2"/> <xsl:apply-templates select="Row3"/> <xsl:apply-templates select="Row4"/> <xsl:apply-templates select="Row5"/> <xsl:apply-templates select="Row6"/> <xsl:apply-templates select="Row7"/> <xsl:apply-templates select="Row8"/> <xsl:apply-templates select="Row9"/>  </table></xsl:template><xsl:template match="Row1"><!--Only displays the Problem Numbers-->     <table class="Row1" border="1" cellspacing="0" cellpadding="3"><tr> 	           <xsl:if test="@problem='yes'">   <td><xsl:apply-templates select="Number1"/>  </td>   <td><xsl:apply-templates select="Number2"/> </td>   <td><xsl:apply-templates select="Number3"/></td>                <td><xsl:apply-templates select="Number4"/></td>                <td><xsl:apply-templates select="Number5"/></td>                <td><xsl:apply-templates select="Number6"/></td>                <td><xsl:apply-templates select="Number7"/></td>                <td><xsl:apply-templates select="Number8"/></td>                <td><xsl:apply-templates select="Number9"/></td></xsl:if>	</tr></table></xsl:template><xsl:template match="Row2">    <table class="Row1" border="1" cellspacing="0" cellpadding="3">	<tr>  <td><xsl:apply-templates select="Number1"/></td>  <td><xsl:apply-templates select="Number2"/></td>  <td><xsl:apply-templates select="Number3"/></td>                <td><xsl:apply-templates select="Number4"/></td>                <td><xsl:apply-templates select="Number5"/></td>                <td><xsl:apply-templates select="Number6"/></td>                <td><xsl:apply-templates select="Number7"/></td>                <td><xsl:apply-templates select="Number8"/></td>                <td><xsl:apply-templates select="Number9"/></td>	</tr></table></xsl:template>

I want it so when i put <XSL: if test="problem=[.'yes']"> it only displays the problem numbers but it doesnt seem to work I have tried to place it in all different places but it either doesnt work or none of the number show not even the table border.

Link to comment
Share on other sites

I told you like thousand times to try and use the XSLT for tabularising linear data. For the sake of completeness:

<?xml version="1.0" encoding="windows-1251"?><!-- DWXMLSource="dictonary.xml" --><!DOCTYPE xsl:stylesheet  [	<!ENTITY nbsp   " ">	<!ENTITY copy   "©">	<!ENTITY reg    "®">	<!ENTITY trade  "™">	<!ENTITY mdash  "—">	<!ENTITY ldquo  "“">	<!ENTITY rdquo  "”"> 	<!ENTITY pound  "£">	<!ENTITY yen    "¥">	<!ENTITY euro   "€">]><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" encoding="windows-1251"doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/><xsl:param name="group-size" select="9" /><xsl:template match="/Sudoku"><html xmlns="http://www.w3.org/1999/xhtml">	<head>		<meta http-equiv="Content-Type" content="text/html; charset=windows-1251"/>		<title>Untitled Document</title>		<style type="text/css">			td {border: 1px solid #000000;}		</style>		</head>		<body> 			<table> 				<xsl:apply-templates select="Row/Number[(position() mod $group-size) = 1]" /> 			</table> 		</body> 	</html> </xsl:template><xsl:template match="Row/Number"> 	<tr> 		<xsl:for-each select=". | following-sibling::Number[position() < $group-size]"> 			<td>				<xsl:choose>					<xsl:when test="@problem='yes'">						<xsl:value-of select="."/>					</xsl:when>					<xsl:otherwise>					 					</xsl:otherwise>				</xsl:choose>			</td> 		</xsl:for-each> 	</tr> </xsl:template></xsl:stylesheet> 

And edit your XML to be something like

<?xml version="1.0"?><Sudoku>	<Row number="1">  <Number problem="yes">1</Number>  <!-- All other numbers on this row below.-->  </Number>	</Row>	<!-- All next rows below.--></Sudoku>

Link to comment
Share on other sites

  • 1 month later...
I told you like thousand times to try and use the XSLT for tabularising linear data. For the sake of completeness:
<?xml version="1.0" encoding="windows-1251"?><!-- DWXMLSource="dictonary.xml" --><!DOCTYPE xsl:stylesheet  [	<!ENTITY nbsp   " ">	<!ENTITY copy   "©">	<!ENTITY reg    "®">	<!ENTITY trade  "™">	<!ENTITY mdash  "—">	<!ENTITY ldquo  "“">	<!ENTITY rdquo  "”"> 	<!ENTITY pound  "£">	<!ENTITY yen    "¥">	<!ENTITY euro   "€">]><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" encoding="windows-1251"doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/><xsl:param name="group-size" select="9" /><xsl:template match="/Sudoku"><html xmlns="http://www.w3.org/1999/xhtml">	<head>  <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"/>  <title>Untitled Document</title>  <style type="text/css">  	td {border: 1px solid #000000;}  </style>  </head>  <body>   	<table>     <xsl:apply-templates select="Row/Number[(position() mod $group-size) = 1]" />   	</table>   </body> 	</html> </xsl:template><xsl:template match="Row/Number"> 	<tr>   <xsl:for-each select=". | following-sibling::Number[position() < $group-size]">   	<td>    <xsl:choose>    	<xsl:when test="@problem='yes'">      <xsl:value-of select="."/>    	</xsl:when>    	<xsl:otherwise>    	     	</xsl:otherwise>    </xsl:choose>  	</td>   </xsl:for-each> 	</tr> </xsl:template></xsl:stylesheet> 

And edit your XML to be something like

<?xml version="1.0"?><Sudoku>	<Row number="1">  <Number problem="yes">1</Number>  <!-- All other numbers on this row below.-->  </Number>	</Row>	<!-- All next rows below.--></Sudoku>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...