Declaring variable namespaces?
You have run into the difference between a node-set (also called a sequence) in XPath and a document. I tried this XPath expression with a sample and it works for me:
<assign outputvariable="$rootElementName" fromexpr="$schemaRootElement/string(@name)"/>
Note that this does not include xsd:element in the path.
The XPath expression you used in the <assign> statement for schemaRootElement extracts one node (could have been several depending on the schema involved). Because there is only one, the variable is in a sense already pointing to the xsd:element node. Thus your expression $schemaRootElement/xsd:element was looking for an element child of the element you extracted -- and that doesn't exist. Hence no output.
Using constructor to wrap a root node around the variable creates a document. For documents, XPath variables point to a position just before the root node. So paths of $var/rootnode work.
Sara, technical writer/jackbe







Hi mashers,
I'm scratching my head a bit over a problem I've struck in an emml I'm working on.
I'm extracting an XML block from an xsd file. The block naturally has a namespace of xmlns:xsd="http://www.w3.org/2001/XMLSchema". I use an assign to pull this out of the xsd file:
<assign fromexpr="$schemaDoc/xsd:schema/xsd:element" outputvariable="$schemaRootElement" />
This is the <display> output from the variable I used to hold this block in:
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:lic.co.nz:herd" name="Herd"
type="Herd">
<xsd:annotation>
<xsd:documentation>Details about an animal herd</xsd:documentation>
</xsd:annotation>
</xsd:element>
I then wanted to extract the element name and expected that I could simply use the following statement:
<assign fromexpr="$schemaRootElement/xsd:element/string(@name)" outputvariable="$rootElementName" />
but this returns no value at all.
I finally found that if I used a <constructor> and wrapped the block between <xsd:root> ... </xsd:root> I could then use the following to get at the element name:
<assign fromexpr="$schemaRootElement/xsd:root/xsd:element/string(@name)" outputvariable="$rootElementName" />
What I don't understand is Why I needed to take these extra steps. I know from debugging that the variable $schemaRootElement does contain the block.
Can anyone shed any light on this. Intuitively I thought my first approach should work.
Thanks as always.
Cheers, Innes (NZ)