XSL Problems

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

XSL Problems

Leon Bezuidenhout
Hi,

I am trying to transform a docuemnt using XSL, but keep getting an error:

[Exception... "Component returns failure code: 0x80600001
[nsIXSLTProcess.importStyleSheet]"
nsresult: "0x80600001 (<unkown>)" location: "JS frame ::
http://devmac1/csp/samples/wab/htmlcontrols/commonxml.js :: anonymous ::
line 49" data: no]

My code looks as follows:

var processor = new XSLTProcessor();
processor.importStylesheet(stylesheet);

And my style sheet looks like htis:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <root>
      <xsl:apply-templates select="/*/*"/>
    </root>
  </xsl:template>
  <xsl:template match="*/*">
    <Record>
      <xsl:attribute name="RecordNo">
        <xsl:value-of select="@rn"/>
      </xsl:attribute>
      <xsl:for-each id="foreach" select="node()">
        <choose xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <when xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
test=".[nodeName() = 'f1']">
            <customerid>
              <value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
            </customerid>
          </when>
          <when xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
test=".[nodeName() = 'f2']">
            <companyname>
              <value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
            </companyname>
          </when>
        </choose>
      </xsl:for-each>
    </Record>
  </xsl:template>
</xsl:transform>

Thanks,
Leon


_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: XSL Problems

Nickolay Ponomarev
On 12/29/06, Leon Bezuidenhout <[hidden email]> wrote:
> [Exception... "Component returns failure code: 0x80600001
> [nsIXSLTProcess.importStyleSheet]"
> nsresult: "0x80600001 (<unkown>)" location: "JS frame ::
> http://devmac1/csp/samples/wab/htmlcontrols/commonxml.js :: anonymous ::
> line 49" data: no]
>
That's NS_ERROR_XSLT_PARSE_FAILURE (see
http://silver.warwickcompsoc.co.uk/mozilla/misc/nserror). Did you
check that your
stylesheet is correct?

It seems to me that you have a "<choose" element without a namespace.

And iirc, you need a select="" attribute on <value-of/> (after putting
that into right namespace too). I don't remember much about XSLT.

Nickolay

> My code looks as follows:
>
> var processor = new XSLTProcessor();
> processor.importStylesheet(stylesheet);
>
> And my style sheet looks like htis:
>
> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:template match="/">
>     <root>
>       <xsl:apply-templates select="/*/*"/>
>     </root>
>   </xsl:template>
>   <xsl:template match="*/*">
>     <Record>
>       <xsl:attribute name="RecordNo">
>         <xsl:value-of select="@rn"/>
>       </xsl:attribute>
>       <xsl:for-each id="foreach" select="node()">
>         <choose xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>           <when xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> test=".[nodeName() = 'f1']">
>             <customerid>
>               <value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
>             </customerid>
>           </when>
>           <when xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> test=".[nodeName() = 'f2']">
>             <companyname>
>               <value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
>             </companyname>
>           </when>
>         </choose>
>       </xsl:for-each>
>     </Record>
>   </xsl:template>
> </xsl:transform>
>
> Thanks,
> Leon
>
>
> _______________________________________________
> dev-tech-xml mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-xml
>
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: XSL Problems

Leon Bezuidenhout
In reply to this post by Leon Bezuidenhout
Thank, I did not even notice that....

The thing is that the document is being constructed dynamically and to
create the node I do this:

var

var oNode = document.implementation.createDocument("","xsl:choose",
null).firstChild;

oNode.setAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform");


Why are my nodes generated without the "xsl:" ? I know I am not setting the
namesoace in the proper manner, but this is the only way I have found that
displays the namespace in my XML.

I'm still new to Mozilla, I have been working with Explorer for the past 4
years, so please excuse the silly questions

Thanks


"Nickolay Ponomarev" <[hidden email]> wrote in message
news:[hidden email]...

> On 12/29/06, Leon Bezuidenhout <[hidden email]> wrote:
>> [Exception... "Component returns failure code: 0x80600001
>> [nsIXSLTProcess.importStyleSheet]"
>> nsresult: "0x80600001 (<unkown>)" location: "JS frame ::
>> http://devmac1/csp/samples/wab/htmlcontrols/commonxml.js :: anonymous ::
>> line 49" data: no]
>>
> That's NS_ERROR_XSLT_PARSE_FAILURE (see
> http://silver.warwickcompsoc.co.uk/mozilla/misc/nserror). Did you
> check that your
> stylesheet is correct?
>
> It seems to me that you have a "<choose" element without a namespace.
>
> And iirc, you need a select="" attribute on <value-of/> (after putting
> that into right namespace too). I don't remember much about XSLT.
>
> Nickolay
>
>> My code looks as follows:
>>
>> var processor = new XSLTProcessor();
>> processor.importStylesheet(stylesheet);
>>
>> And my style sheet looks like htis:
>>
>> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>>   <xsl:template match="/">
>>     <root>
>>       <xsl:apply-templates select="/*/*"/>
>>     </root>
>>   </xsl:template>
>>   <xsl:template match="*/*">
>>     <Record>
>>       <xsl:attribute name="RecordNo">
>>         <xsl:value-of select="@rn"/>
>>       </xsl:attribute>
>>       <xsl:for-each id="foreach" select="node()">
>>         <choose xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>>           <when xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> test=".[nodeName() = 'f1']">
>>             <customerid>
>>               <value-of
>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
>>             </customerid>
>>           </when>
>>           <when xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> test=".[nodeName() = 'f2']">
>>             <companyname>
>>               <value-of
>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
>>             </companyname>
>>           </when>
>>         </choose>
>>       </xsl:for-each>
>>     </Record>
>>   </xsl:template>
>> </xsl:transform>
>>
>> Thanks,
>> Leon
>>
>>
>> _______________________________________________
>> dev-tech-xml mailing list
>> [hidden email]
>> https://lists.mozilla.org/listinfo/dev-tech-xml
>>


_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: XSL Problems

Nickolay Ponomarev
You should read something on XML namespaces and working with them from DOM.

In particular, you use createDocument wrong (see
http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocument
) and you should use createElementNS instead of setting xmlns:*
attributes on elements.

In general, I think it's pretty hard to generate an XSLT dynamically like this.

Nickolay

On 12/29/06, Leon Bezuidenhout <[hidden email]> wrote:

> Thank, I did not even notice that....
>
> The thing is that the document is being constructed dynamically and to
> create the node I do this:
>
> var
>
> var oNode = document.implementation.createDocument("","xsl:choose",
> null).firstChild;
>
> oNode.setAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform");
>
>
> Why are my nodes generated without the "xsl:" ? I know I am not setting the
> namesoace in the proper manner, but this is the only way I have found that
> displays the namespace in my XML.
>
> I'm still new to Mozilla, I have been working with Explorer for the past 4
> years, so please excuse the silly questions
>
> Thanks
>
>
> "Nickolay Ponomarev" <[hidden email]> wrote in message
> news:[hidden email]...
> > On 12/29/06, Leon Bezuidenhout <[hidden email]> wrote:
> >> [Exception... "Component returns failure code: 0x80600001
> >> [nsIXSLTProcess.importStyleSheet]"
> >> nsresult: "0x80600001 (<unkown>)" location: "JS frame ::
> >> http://devmac1/csp/samples/wab/htmlcontrols/commonxml.js :: anonymous ::
> >> line 49" data: no]
> >>
> > That's NS_ERROR_XSLT_PARSE_FAILURE (see
> > http://silver.warwickcompsoc.co.uk/mozilla/misc/nserror). Did you
> > check that your
> > stylesheet is correct?
> >
> > It seems to me that you have a "<choose" element without a namespace.
> >
> > And iirc, you need a select="" attribute on <value-of/> (after putting
> > that into right namespace too). I don't remember much about XSLT.
> >
> > Nickolay
> >
> >> My code looks as follows:
> >>
> >> var processor = new XSLTProcessor();
> >> processor.importStylesheet(stylesheet);
> >>
> >> And my style sheet looks like htis:
> >>
> >> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> >>   <xsl:template match="/">
> >>     <root>
> >>       <xsl:apply-templates select="/*/*"/>
> >>     </root>
> >>   </xsl:template>
> >>   <xsl:template match="*/*">
> >>     <Record>
> >>       <xsl:attribute name="RecordNo">
> >>         <xsl:value-of select="@rn"/>
> >>       </xsl:attribute>
> >>       <xsl:for-each id="foreach" select="node()">
> >>         <choose xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> >>           <when xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >> test=".[nodeName() = 'f1']">
> >>             <customerid>
> >>               <value-of
> >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
> >>             </customerid>
> >>           </when>
> >>           <when xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >> test=".[nodeName() = 'f2']">
> >>             <companyname>
> >>               <value-of
> >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
> >>             </companyname>
> >>           </when>
> >>         </choose>
> >>       </xsl:for-each>
> >>     </Record>
> >>   </xsl:template>
> >> </xsl:transform>
> >>
> >> Thanks,
> >> Leon
> >>
> >>
> >> _______________________________________________
> >> dev-tech-xml mailing list
> >> [hidden email]
> >> https://lists.mozilla.org/listinfo/dev-tech-xml
> >>
>
>
> _______________________________________________
> dev-tech-xml mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-xml
>
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: XSL Problems

Martin Honnen-3
In reply to this post by Leon Bezuidenhout
Leon Bezuidenhout wrote:

> var oNode = document.implementation.createDocument("","xsl:choose",
> null).firstChild;
>
> oNode.setAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform");
>
>
> Why are my nodes generated without the "xsl:" ? I know I am not setting the
> namesoace in the proper manner, but this is the only way I have found that
> displays the namespace in my XML.

Use namespace aware DOM Level 2 methods like createElementNS and then
make sure you pass in namespace URIs where required e.g.

var xslNs = 'http://www.w3.org/1999/XSL/Transform';

var stylesheet = document.implementation.createDocument(xslNs,
'xsl:stylesheet', null);

stylesheet.documentElement.setAttributeNS(null, 'version', '1.0');

var template = stylesheet.createElementNS(xslNs, 'xsl:template');
template.setAttributeNS(null, 'match', '@* | node()');
var copy = stylesheet.createElementNS(xslNs, 'xsl:copy');
var applyTemplates = stylesheet.createElementNS(xslNs,
'xsl:apply-templates');
applyTemplates.setAttributeNS(null, 'select', '@* | node()');
copy.appendChild(applyTemplates);
template.appendChild(copy);

stylesheet.documentElement.appendChild(template);

So every time you create an element you need to pass in the proper
namespace URI as the namespace of an element is determined when it is
created.



--

        Martin Honnen
        http://JavaScript.FAQTs.com/
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: XSL Problems

Leon Bezuidenhout
Thanks,

This helped a lot :o)

Last question on the matter, since my code is still failing :o(

My XSL document is half pre-defined, half run time defined and it is still
giving problems



"Martin Honnen" <[hidden email]> wrote in message
news:[hidden email]...

> Leon Bezuidenhout wrote:
>
>> var oNode = document.implementation.createDocument("","xsl:choose",
>> null).firstChild;
>>
>> oNode.setAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform");
>>
>>
>> Why are my nodes generated without the "xsl:" ? I know I am not setting
>> the namesoace in the proper manner, but this is the only way I have found
>> that displays the namespace in my XML.
>
> Use namespace aware DOM Level 2 methods like createElementNS and then make
> sure you pass in namespace URIs where required e.g.
>
> var xslNs = 'http://www.w3.org/1999/XSL/Transform';
>
> var stylesheet = document.implementation.createDocument(xslNs,
> 'xsl:stylesheet', null);
>
> stylesheet.documentElement.setAttributeNS(null, 'version', '1.0');
>
> var template = stylesheet.createElementNS(xslNs, 'xsl:template');
> template.setAttributeNS(null, 'match', '@* | node()');
> var copy = stylesheet.createElementNS(xslNs, 'xsl:copy');
> var applyTemplates = stylesheet.createElementNS(xslNs,
> 'xsl:apply-templates');
> applyTemplates.setAttributeNS(null, 'select', '@* | node()');
> copy.appendChild(applyTemplates);
> template.appendChild(copy);
>
> stylesheet.documentElement.appendChild(template);
>
> So every time you create an element you need to pass in the proper
> namespace URI as the namespace of an element is determined when it is
> created.
>
>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/ 


_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml