CSCI 5733.1
XML Application Development
Summer 2003
Suggested Solution to Final Examination
(1) For example,
<!-- Your XSL code here -->
<!-- Your XSL code here -->
<xsl:template match="/">
<xsl:apply-templates select="*" mode="root"/>
</xsl:template>
<xsl:template match="*" mode="root">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="descendant::*"
mode="other" />
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="other">
<xsl:copy>
<xsl:apply-templates select="@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:copy />
</xsl:template>
<!--
<xsl:template match="text()" />
-->
(2) For example:
(a) //book[authorRef/@id=//author[text()="Bun Yue"]/@id]/@isbn
(b) //author[starts-with(text(),"Sadegh")]
(c) //category[@id=//book[title/text()="Fun with XML"]/categoryRef/@id]/text()
(d) count(//book) - count(//book[categoryRef/@id="c3"])
(e) //book[not(authorRef)]
(3) For example,
private static Vector getPIs(Node node) {
if (node == null) return null;
Vector result = new Vector();
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.ELEMENT_NODE:
NodeList
children = node.getChildNodes();
for (int
i=0; i<children.getLength(); i++)
{
Vector childPIs = getPIs(children.item(i));
if (childPIs != null) result.addAll(childPIs);
}
return result;
case Node.PROCESSING_INSTRUCTION_NODE:
result.add(node);
return result;
}
return null;
} // getPIs