I am new to this whole XSLT thing, however I love it lots so far. I am getting confused when it comes to accessing parameters to XML nested within others.
XML file to be transformed (simplified)
Code:
<form width="60%" align="center" method="post" action="request.php">
<line>
<desc required="true">Name:</desc>
<entry>
<input type="text" name="name" size="50" maxlength="50" value="<?=$name?>"/>
</entry>
</line>
<line>
<desc/>
<entry align="center">
Full: [First Middle Last]
</entry>
</line>
</form>
The XSLT for the transformation.
Code:
<xsl:template match="body//form">
<form method="" action="">
<xsl:if test="@method">
<xsl:attribute name="method">
<xsl:value-of select="@method"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@action">
<xsl:attribute name="action">
<xsl:value-of select="@action"/>
</xsl:attribute>
</xsl:if>
<table width="100%" align="center">
<xsl:if test="@width">
<xsl:attribute name="width">
<xsl:value-of select="@width"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()[not(self::line)]|@*|text()"/>
<xsl:for-each select="line">
<tr>
<xsl:call-template name="desc"/>
<xsl:call-template name="entry"/>
</tr>
</xsl:for-each>
</table>
</form>
</xsl:template>
<xsl:template name="desc">
<td align="left">
----> <xsl:if test="@required = true">
<star/>
</xsl:if>
<xsl:apply-templates select="desc"/>
</td>
</xsl:template>
<xsl:template name="entry">
<td align="right">
-----> <xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="entry"/>
</td>
</xsl:template>
The problem I am having is that within the 'desc' and 'entry' templates the if's for the parameters are never being called.
I assumed since:
<desc required="true">
that
<xsl:if test="@required = true">
Should work, but it's not. Why and how do I fix it?
--
dave