2

Getting the following error in an XSL transform for a REST databroker:

org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.

Here's the XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="PCIresponse">
    <dataset>
     <xsl:for-each select="account-set/account">
      <row> 
         <xsl:element name="field">
           <xsl:attribute name="name">name</xsl:attribute>
           <xsl:attribute name="value"><xsl:value-of select="Account_Name" /></xsl:attribute>
         </xsl:element>
      </row>
     </xsl:for-each>
  </dataset>
</xsl:template>
Adam Sharp
  • 3,618
  • 25
  • 29
savs
  • 202
  • 1
  • 8

1 Answers1

2

It turns out that the Java XSL handler does not like any white space before the first node of the generated transform.

To fix the problem you set the root node first (that is, the node) using its own top-level template, and use apply-templates from there. The working version looks like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="account-set">
     <xsl:for-each select="account">
      <row> 
            <xsl:element name="field">
                  <xsl:attribute name="name">name</xsl:attribute>
                  <xsl:attribute name="value"><xsl:value-of select="Account_Name" /></xsl:attribute>
                </xsl:element>          
      </row>
     </xsl:for-each>
 </xsl:template>

 <xsl:template match="PCIresponse">
    <dataset>
      <xsl:apply-templates/>
    </dataset>
  </xsl:template>

</xsl:stylesheet>

The best summary of this solution is at: http://servicemix.apache.org/servicemix-saxon-orgw3cdomdomexception-hierarchyrequesterr.html

savs
  • 202
  • 1
  • 8