CSCI 5733.1
XML Application Development
Fall 2002
Suggested Solution to Final Examination
(1) For example,
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" version="1.0" indent="yes" />
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*[.='x']" >
<xsl:copy />
</xsl:template>
<xsl:template match="@*" />
</xsl:stylesheet>
(2) For example.
(a) //person[count(email)>1]
(b) //person[@ssn=//person[first/text()="Boris" and last/text()="Becker"]/link/@spouse]/first
(c) count(//person[@gender='F'])
(d) //*[not(@*)]
(e) //person[@ssn="s111222333"]/following-sibling::person[1]
(3) For example,
if (element == null) return 0;
Iterator iterator = element.getChildren().iterator();
int descendantCount = 0;
while (iterator.hasNext()) {
Element childElement = (Element)
iterator.next();
descendantCount += addDescendantCount(childElement)
+ 1;
}
element.setAttribute("numDescendants", (new Integer(descendantCount)).toString());
return descendantCount;
} // addDescendantCount