XSL question about handling (with server error :)
I have what I think is an interesting situation. I have a garage for a garage and am converting it (using XSL) to HTML.
CAR XML:
<car>
<licensePlate>Car001</licensePlate>
<feature>
<color>Blue</color>
<fuel>Unleaded</fuel>
<feature>
</car>
I only want to print <color>
and <fuel>
but want to set <licensePlate>
as href in HTML link.
CAR XSL:
<xsl:template match="car">
<tr>
<xsl:apply-templates select="licensePlate"/>
<xsl:apply-templates select="feature"/>
</tr>
</xsl:template>
<xsl:template match="feature">
<td>
<a href="{preceding-sibling::licensePlate/text()}>
<xsl:apply-templates select="color"/>
</a>
</td>
<td><xsl:apply-templates select="fuel"/></td>
</xsl:template>
This allows me to achieve my goal of setting the tag as the href value.
BUT the problem occurs ... all licensePlate values are printed to the screen.
Can anyone recommend how to prevent it from printing on the screen?
I tried commenting <xsl:apply-templates select="licensePlate"/>
, but I think it is affecting the operator preceeding-sibling::
as I am getting the error
I also got this error when trying to apply CSS display:none
.
Thanks for your time and patience, Lucas.
a source to share
Here's one way to do it. I am assuming you have color and fuel templates already made.
<xsl:template match="car">
<tr>
<xsl:apply-templates select="feature"/>
</tr>
</xsl:template>
<xsl:template match="feature">
<td>
<a>
<xsl:param name="href">
<xsl:value-of select="../licensePlate"/>
</xsl:param>
<xsl:apply-templates select="color"/>
</a>
</td>
<td>
<xsl:apply-templates select="fuel"/>
</td>
</xsl:template>
a source to share
<xsl:template match="car">
<tr>
<xsl:apply-templates select="feature" />
</tr>
</xsl:template>
<xsl:template match="feature">
<td>
<a href="{../licensePlate}">
<xsl:value-of select="color" />
</a>
</td>
<td>
<xsl:value-of select="fuel" />
</td>
</xsl:template>
Produces:
<tr>
<td>
<a href="Car001">Blue</a>
</td>
<td>Unleaded</td>
</tr>
a source to share