I have a problem with linking foreign key IDREF from xml TO XSLT. I have tried in many ways to solve that problem. But still when I display it, I cannot see my IDREF from XSLT. For example the code below should display patient doctor-reference d1,d2 ...etc.But it does not display anything from the doctor .can anyone help me to solve it ??
Here is my code for xml :
<patient unique_no="p1" gender="F">
<f_name>MMA</f_name>
<l_name>STONE</l_name>
<doctor-ref IDREF="d1"/>
<doctor-ref IDREF="d2"/>
</patient>
<doctor id="d1">
<d_f_name>Chef Linguini</d_f_name>
<d_l_name>Gusteau</d_l_name>
<specification>&on;</specification>
</doctor>
<doctor id="d2">
<d_f_name>Gordon</d_f_name>
<d_l_name>Ramsay</d_l_name>
<specification>&ENT;</specification>
</doctor>
<xsl:template match="/">
<xsl:for-each select="hospital/patient">
<xsl:sort select="f_name" />
<tr>
<td>
<xsl:value-of select="@unique_no" />
</td>
<td>
<xsl:value-of select="f_name" />
</td>
<td>
<xsl:value-of select="l_name" />
</td>
<xsl:choose>
<xsl:when test="@gender='M'">
<td bgcolor="red">
<xsl:value-of select="@gender"/></td>
</xsl:when>
<xsl:when test="@gender='F'">
<td bgcolor="Yellow">
<xsl:value-of select="@gender"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="@gender"/></td>
</xsl:otherwise>
</xsl:choose>
<!-- <td>
<xsl:value-of select="@gender" />
</td> -->
<td>
<!-- <xsl:value-of select="key('Medications', @Medications/@IDREF)"/>
-->
<xsl:value-of select="@Medications"/>
</td>
<td>
<xsl:value-of select="@doctor" />
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</xsl:template>
My output should have show doctor idref also .But it did not show.Why? enter image description here
The
<doctor>
node is a sibling of<patient>
node i.e. both are at the same level under the<hospital>
node. In order to access the<doctor>
node from within the<patient>
loop,XPath axes
can be used.In this scenario, since the required output is not shared, the assumption is that you need either the
@IDREF
or thedoctor name
in your output. Using the same XSL the below can be done to access the<doctor>
nodes. Depending on the output the XSL code within the<td>
can be retained or discarded.This gives the output as below