Yesterday I got asked by a colleague why DataPower XSLT processor complained about
"Illegal Pattern: Axis parent is illegal, only child and attribute are allowed"
when using a parent step in a XPath expression.
when using a parent step in a XPath expression.
I created a simple sample and did not get the error.
The problem to solve is to act on the <CustomField>'s <Value> child who's <Name> child has a specific value only.
The problem to solve is to act on the <CustomField>'s <Value> child who's <Name> child has a specific value only.
Here is the simple stylesheet I created first:
As can be seen the correct <Value> just gets extracted from data.xml:
Then I got the problematic stylesheet from my colleague and the difference was, that he used the same XPath expression,
|
but inside a template match Pattern (see spec).
This is a simple problematic stylesheet resulting in "Illegal Pattern: Axis parent is illegal, only child and attribute are allowed" eror message:
This is a simple problematic stylesheet resulting in "Illegal Pattern: Axis parent is illegal, only child and attribute are allowed" eror message:
OK, so parent step ("..") is not allowed by the spec, but I needed to provide a working solution to my colleague.
The trick is not to match on the <Name> element of interest first, that is already too deep.
Instead matching on the common predecessor (parent) of <Name> and <Value>, <CustomField> and
reformulating the XPath expression does solve the problem, see solution.xsl:
Instead matching on the common predecessor (parent) of <Name> and <Value>, <CustomField> and
reformulating the XPath expression does solve the problem, see solution.xsl:
You can see here that everything works fine with the modified match pattern:
Hermann < myXsltBlog/> < myXsltTweets/>
<data> <CustomField> <Name>xx</Name> <Value>11</Value> </CustomField> <new>22</new> </data> $ |