K
Kolossi
After reading lots of helpful posts here, and www.dpawson.co.uk, I
think I've got the hang of processing exceptions to the identity
transform (I'll call it "identity-"), but have a reasonably
straightforward problem that I'd like to find the most elegant solution
to.
I need to do an identity transform, but if certain elements are
missing, add them, (I'll call this "identity+"). Since XSL rules are
based on matching elements, I can't see how to code a rule as an
exception to the identity transform if I haven't got any input to match
it on.
Here's an example. I want to copy the input, but if it doesn't have an
<author> element anywhere under the root node, I want to add one at the
end, so I want to turn
<a>
<b>foo</b>
<c>bar</c>
<d>boof</d>
</a>
into
<a>
<b>foo</b>
<c>bar</c>
<d>boof</d>
<author>UNKNOWN</author>
</a>
but just identity transform
<a>
<author>me<author>
<e>1</e>
<f>2</f>
</a>
into
<a>
<author>me<author>
<e>1</e>
<f>2</f>
</a>
If I knew all the possible elements below the root node, I guess I
could match the root node, then explicitly copy them all and add the
<author> element at the end if I hadn't set a variable to say I'd found
one, but I'm hoping there is a more elegant solution.
TIA
Paul Sweeney
think I've got the hang of processing exceptions to the identity
transform (I'll call it "identity-"), but have a reasonably
straightforward problem that I'd like to find the most elegant solution
to.
I need to do an identity transform, but if certain elements are
missing, add them, (I'll call this "identity+"). Since XSL rules are
based on matching elements, I can't see how to code a rule as an
exception to the identity transform if I haven't got any input to match
it on.
Here's an example. I want to copy the input, but if it doesn't have an
<author> element anywhere under the root node, I want to add one at the
end, so I want to turn
<a>
<b>foo</b>
<c>bar</c>
<d>boof</d>
</a>
into
<a>
<b>foo</b>
<c>bar</c>
<d>boof</d>
<author>UNKNOWN</author>
</a>
but just identity transform
<a>
<author>me<author>
<e>1</e>
<f>2</f>
</a>
into
<a>
<author>me<author>
<e>1</e>
<f>2</f>
</a>
If I knew all the possible elements below the root node, I guess I
could match the root node, then explicitly copy them all and add the
<author> element at the end if I hadn't set a variable to say I'd found
one, but I'm hoping there is a more elegant solution.
TIA
Paul Sweeney