PDA

View Full Version : Deciding which node is in XML with XSLT


cotec
08-09-2005, 05:16 PM
I have 2 XML documents that differ by a single type of node. In one of the documents, I have a <Score> node within a <Student> node. In the other doc, I have a <Complete> node withing the Student.

I know I need to use the <xsl:if> tag to check for these items, but how do I check for the node's name instead of the attribute? I know beforehand that the Student node will have one of the 2 options, but not both.

Thank you in advance,
Chris

Here is a small snippet of how each XML file looks:


<Report>
<Student>
<Name>Cote, Chris</Name>
<Score>86</Score>
</Student>
<Student>
<Name>Doe, John</Name>
<Score>79</Score>
</Student>
</Report>


And the 2nd document:

<Report>
<Student>
<Name>Cote, Chris</Name>
<Complete>True</Complete>
</Student>
<Student>
<Name>Doe, John</Name>
<Complete>False</Complete>
</Student>
</Report>

hemebond
08-09-2005, 10:25 PM
Can I see the XSLT file so I know what you're trying to do with this data?

werD
08-10-2005, 05:43 PM
Basic If example

<xsl:if test="Score">Do Your Task</xsl:if>
<xsl:if test="Complete">Do Your other Task</xsl:if>


Basic When/Otherwise Example


<xsl:choose>
<xsl:when test="Score">
Score is:<xsl:value-of select="Score"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="Complete='True'">
You have completed this
</xsl:if>
<xsl:if test="Complete='False'">
You have not completed this
</xsl:if>
</xsl:otherwise>
</xsl:choose>


I tried to put some other basic examples in there too