|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Checking for elements
XSLT works for this kind of thing and its pretty easy, too. Say the file data.xml is expected to contain the elements cow and chicken but it doesn't: C:\XML\Examples>cat data.xml <data> <pig/> <chicken/> <horse/> </data> Here's an XSLT stylesheet that checks for the the cow and chicken elements in data.xml: C:\XML\Examples>cat check.xsl <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="data"> <xsl:choose> <xsl:when test="not(chicken)"> <xsl:message>chicken element not found</xsl:message> </xsl:when> <xsl:when test="not(cow)"> <xsl:message>cow element not found</xsl:message> </xsl:when> <xsl:otherwise> <xsl:message>All needed elements found</xsl:message> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> If data.xml contains both cow and chicken, you'll get a report saying that all the needed elements are found. If not, you get a complaint: C:\XML\Examples>saxon data.xml check.xsl cow element not found Hope this works for you. Mike Noah Genner wrote: > Hello All, > I'm new to all this and I'm looking for some direction. > I need to be able to check an XML document for some specific elements, and if > possible produce a little report on which ones are missing. The document has > already been validated against a dtd/schema that contains approximately 270 > elements, but I need to check that the ~40 I need are present. If they aren't > present I want to produce a little report that says which elements are not present. > Can I do this with XSLT, or is there an easier way to do this? > > Thanks, >
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








