I need your help for a question about XSLT. It is part of my exam preparation. The information given is as follows: HTML rendering of the XML document from Figure 1. Note that groups, and staff within each group, appear in the same order as in the XML document. At the end of each staff member entry, there are the identifiers of other groups to which the academic also belongs. These are hyperlinked to the start of the corresponding group sections. The final result of applying XSLT must be:
The XML file is as follows:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="research.xsl"?>
<ResearchGroups xmlns="http://ift.tt/1tywXRg">
<Group name="Intelligent Systems Group" id="ISG"> The Intelligent
Systems Group pursues internationally-leading research in a wide
range of intelligent systems. </Group>
<Group name="Robotics" id="RBT"> The Essex robotics group is one of
the largest mobile robotics groups in the UK. </Group>
<Staff name="Callaghan, Vic" title="Professor" groups="ISG RBT">
Intelligent environments and robotics. </Staff>
<Staff name="Gu, Dongbing" title="Dr" groups="RBT"> Multi-agent
and distributed control systems. </Staff>
</ResearchGroups>
The .xsl file I have created is as follows:
<xsl:stylesheet
xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:rg="http://ift.tt/1tywXRg"
xmlns="http://ift.tt/1tywXRi"
version="2.0">
<xsl:template match="/">
<html>
<head> <title>Research Groups</title> </head>
<body> <xsl:apply-templates select="//rg:Group"/>
</body>
</html>
</xsl:template>
<xsl:template match="rg:Group">
<xsl:variable name="ID" select="@id"/>
<h3> <a name="{$ID}"> <xsl:value-of select="@name"/> </a> </h3>
<p> <xsl:value-of select="text()"/> </p>
<xsl:for-each select="//rg:Staff">
<xsl:variable name="string" select="@groups" />
<xsl:value-of select="$string" />
<xsl:variable name="stringList" select="tokenize($string, ' ')" />
<xsl:variable name="staffName" select="@name" />
<xsl:variable name="description" select="text()" />
<xsl:for-each select="$stringList">
<xsl:variable name="item" select="." />
<xsl:choose>
<xsl:when test="matches($item, $ID)">
<ul>
<li>
<xsl:value-of select="$staffName" />: <xsl:value-of select="$description" />
<xsl:value-of select="$ID" />
</li>
</ul>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The problem I have is with the part "At the end of each staff member entry, there are the identifiers of other groups to which the academic also belongs. These are hyperlinked to the start of the corresponding group sections." Because the first staff member belongs to two groups while the second does not. I hope that somebody can help me! Thank you in advance.
No comments:
Post a Comment