jjasper0729
jjasper0729

Reputation: 295

xsl 1.0 Why won't a node match return data

I'm using the following xml information:

<section>
  <...>
</section>
<section>
  <templateId root="2.16.840.1.113883.10.20.22.2.10" />
  <text>
    <table id="Appointments">
      <tr>
        <td id="heading">Appointments</td>
      </tr>
      <tr>
        <td id="content">No future appointments scheduled.</td>
      </tr>
    </table>
    <br />
    <table id="Referrals">
      <tr>
        <td id="heading">Referrals</td>
      </tr>
      <tr>
        <td id="content">No referrals available.</td>
      </tr>
    </table>
    <br />
  </text>
<section>
<section>
  <...>
</section>

There are multiple section nodes (with their own child nodes, including templateId) within the document. I'm having trouble with this one so I wanted to be specific in the xml information.

and in my xslt file I want to get one particular table out. I'm referencing it the following way (I'm trying to use templates and I'm new to XSL so please bear with me)

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns="http://www.w3.org/1999/xhtml">


<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
  <xsl:apply-templates select="//section[templateId/@root='2.16.840.1.113883.10.20.22.2.17']/text/table[@id='Appointments']" />
</xsl: template>

<xsl:template match="section[templateId/@root='2.16.840.1.113883.10.20.22.2.17']/text/table[@id='Appointments']">
  <div style="float: left; width: 50%;">
    <span style="font-weight: bold;">
    <xsl:value-of select="tr/td[@id='heading']"/>:
    </span>
    <br />
    <xsl:call-template name="replace">
      <xsl:with-param name="string" select="tr/td[@id='content']"/>
    </xsl:call-template>
    </div>
</xsl:template>

<xsl:template name="replace">
  <xsl:param name="string"/>
  <xsl:choose>
    <xsl:when test="contains($string,'&#10;')">
      <xsl:value-of select="substring-before($string,'&#10;')"/>
      <br/>
      <xsl:call-template name="replace">
        <xsl:with-param name="string" select="substring-after($string,'&#10;')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>

In this particular xml example, the output should be:

Appointments:
No future appointments scheduled.

I'm thinking the match and select need some tweaking but not sure what part.

Also, if the template can be tweaked so that I could pass a parameter with the table/@id value so that I could reuse this one template for a couple of items,that would be even more beneficial (the output for referrals and appointments that are in this example would be the same).

Thanks for any help

Upvotes: 0

Views: 207

Answers (1)

Kevin Brown
Kevin Brown

Reputation: 8877

This is your XML section root attribute (cut and paste from your XML):

 root="2.16.840.1.113883.10.20.22.2.10" 

This is your test XSL:

 root='2.16.840.1.113883.10.20.22.2.17'

Of course they do not match, one ends with "10", the other with "17"

Changing the data to "17" and correcting the other errors in my comments yields:

 <div style="float: left; width: 50%;"><span style="font-weight: bold;">Appointments:
       </span><br>No future appointments scheduled.
 </div

Upvotes: 1

Related Questions