Subject: Re: [xsl] Distinguish between empty string and no children, in XPath 2? From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx> Date: Fri, 5 Sep 2008 13:58:02 +0100 |
>> Let's say we have a schema (maybe expressed in XML Schema, but not >> necessarily so), that allows this instance document: >> >> <top> >> <txt>This is text</txt> >> <books> >> <book>Tarzan</book> >> <book>Harry Potter</book> >> </books> >> </top> >> >> The text /top/txt may be empty, and the element /top/books may have no >> children, so this instance document is also allowed: >> >> <top> >> <txt/> >> <books/> >> </top> >> >> I now want to write an XPath expression that selects all nodes that do >> not have child elements in the schema. It would always select /top/txt >> and it would never select /top/books, even in the second example >> above. >> >> With XPath 1.0, this is not possible, since schema information is not >> used there. But can it be done in XPath 2.0? Ken: > Unless, perhaps, you had the flexibility in your schema to define a base > type with your own name that is a very generic type that allows only element > children of any name, and then specialize all of your element-content > element types on that type restricting each one to the child elements for > that particular type. Then in your XPath you can test elements as being an > element of your named generic type and it would be checking that the element > is one that has element content. Instead of applying the xpath to the instance document, don't you just want to apply it to the schema - select all simpleTypes ? I don't know if you can tell from the PSVI whether a given type is a simpleType or complexType, but that would do it... maybe "castable as xs:anyAtomicType" ? Just thinking out loud... -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Distinguish between empty, G. Ken Holman | Thread | RE: [xsl] Distinguish between empty, Michael Kay |
[xsl] for-each-group and result-doc, James Cummings | Date | RE: [xsl] Distinguish between empty, Michael Kay |
Month |