tags:

views:

123

answers:

3

Hi there, I have, what I believe to be, an interesting situation at hand. I have a car garage XML and am transforming it (using XSL) into HTML.

CAR XML:

<car>
   <licensePlate>Car001</licensePlate>
   <feature>
      <color>Blue</color>
      <fuel>Unleaded</fuel>
   <feature>
</car>

I only want to print out <color> & <fuel> but want to set the <licensePlate> as href in a 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 enables me to achieve my goal of setting the tag as the href value.

BUT a problem occurs...all of the values of licensePlate are printed to screen.

Can someone recommend how to prevent it from printing to screen?

I have tried commenting out <xsl:apply-templates select="licensePlate"/> but I think this affects the preceeding-sibling:: statement as I receive an error

I have also received this error when trying to apply a CSS display:none.

Thankyou for your time and patience, Lucas

+1  A: 

You should comment out <xsl:apply-templates select="licensePlate"/>. It couldn't be the cause of the error if you commented it out correctly.

Also: <a href="{preceding-sibling::licensePlate/text()}> <-- yuikes!

<a href="{../licensePlate}>!

alamar
Alamar, thankyou for your speedy response.Would that still work as it is not a child element within <feature> but a sibling of <feature>
Lycana
@lucas: ".." means "parent", not "child".
Tomalak
Sure!Access to child element would be just `{licensePlate}`.
alamar
I tried your suggestion: I still get the same error:com.sun.xml.internal.ws.client.ClientTransportEception: The server sent HTTP status code -1: null.
Lycana
A: 
<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>

Would produce:

<tr>
  <td>
    <a href="Car001">Blue</a>
  </td>
  <td>Unleaded</td>
</tr>
Tomalak
I tried your suggestion: I still get the same error:com.sun.xml.internal.ws.client.ClientTransportEception: The server sent HTTP status code -1: null.
Lycana
I was missing a closing double quote. Can you try again?
Tomalak
A: 

Here's one way to do it. I'm assuming you have the templates for color and fuel already done.

<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>
Kyle Walsh
I tried your suggestion: I still get the same error:com.sun.xml.internal.ws.client.ClientTransportEception: The server sent HTTP status code -1: null.
Lycana
Above I mentioned my assumption that you already have templates for color and fuel. Is this true? If so, could you post them? Any extra info would be helpful!
Kyle Walsh