You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Sergey S. Kljopov" <kl...@wetellyou.com> on 2000/10/25 14:19:35 UTC

ElemAttribute

Hi!

Here is some part of ElemAttribute.java file:
  public void execute([skipped])
        throws [skipped] {
    super.execute(processor, sourceTree, sourceNode, mode);
    XPathSupport execContext = processor.getXMLProcessorLiaison();
    String attrName = m_name_avt.evaluate(execContext, sourceNode, this,
                                          new StringBuffer());
    String origAttrName = attrName;      // save original attribute name
    int indexOfNSSep = 0;
/** 1st if */
    if(null != attrName) {
      String attrNameSpace = null;
      if(null != m_namespace_avt) {
        attrNameSpace = m_namespace_avt.evaluate(execContext, sourceNode, this,
                                                        new StringBuffer());
/** 2nd if */
        if(null != attrNameSpace && attrNameSpace.length()>0) {
          String prefix = processor.getResultPrefixForNamespace(attrNameSpace);
          if(null == prefix) {
            prefix = "ns"+String.valueOf(processor.m_uniqueNSValue);
            processor.m_uniqueNSValue++;
            String nsDecl = "xmlns:"+prefix;

            // Not sure this should go through the aliasing comment.
            //addResultAttribute(processor.m_resultNameSpaces,
            processor.addResultAttribute(
                               processor.m_pendingAttributes,
                               nsDecl, attrNameSpace);
          }
          indexOfNSSep = origAttrName.indexOf(':');
          if(indexOfNSSep >= 0)
            attrName = attrName.substring(indexOfNSSep+1);
          attrName = (prefix + ":"+attrName);       // add prefix to attribute name
        }
      }
      // Note we are using original attribute name for these tests.
/** 1st else */
      else if(null != processor.m_pendingElementName && !origAttrName.equals("xmlns")) {
        // make sure that if a prefix is specified on the attribute name, it is valid
        indexOfNSSep = origAttrName.indexOf(':');
        if(indexOfNSSep >= 0) {
          String nsprefix = origAttrName.substring(0, indexOfNSSep);
          // Catch the exception this may cause. We don't want to stop processing.
          try{
            attrNameSpace = getNamespaceForPrefix(nsprefix);
          }
          catch(Exception ex) {
            // Could not resolve prefix
            attrNameSpace = null;
            processor.warn(XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX, new Object[]{nsprefix});
          }
        }
      }
/** 2nd else */
      else {
        processor.warn(XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_NAME, new Object[]{origAttrName});
        // warn(templateChild, sourceNode, "Trying to add attribute after element child has been added, ignoring...");
      }
/** 3rd if*/
      if (indexOfNSSep<0 || attrNameSpace != null) {
        String val = childrenToString(processor, sourceTree, sourceNode, mode);
      }
    }
  }

I have a xsl file with tag <xsl:attribite name="href">. So attrName == "href".
Apache JServ gives me XSL Warning: Illegal attribute name: href
Let me look through this code. At first, i'm fall into the 1st if block because attrName == "href", not null. At second i pass the 2nd if block because attrNameSpace for my attrName == null. Than... at Apache JServ i'm fall into the 2nd else so i can see XSL Warning, but if i test my processor and xsl locally on the JBuilder's servlet engine i do not receive this warning because i'm fall into the 1st else block (this is checked) and into the 3rd if block after all (because indexOfNSSep which is ':' == -1)
Why i receive warning on apache and is this bad warning? Can i switch off this else simply?

WBR, Sergey S. Kljopov

-VALIDATE in command line arguments

Posted by "K. Ari Krupnikov" <ar...@iln.net>.
This would certainly appears to be a FAQ, but I haven't been able to
find the answer in the archives.

I run org.apache.xalan.xslt.Process from the command line with -VALIDATE
as one of the parameters.

1). Can I get Xalan (or rather Xerces) to validate only the document,
but not the stylesheet?

2). I get the following error:
Parser error: General Schema Error: Grammar with uri :
http://www.w3.org/1999/XSL/Transform , can not found. 

My stylesheet starts with:

<xsl:transform
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	version="1.0"
>

-- 
K. Ari Krupnikov

DBDOM - bridging XML and relational databases
http://www.iter.co.il

Re: ElemAttribute

Posted by "Sergey S. Kljopov" <kl...@wetellyou.com>.
Hi!

> If you hardcode the xsl:import elements into the stylesheets just for
> the test, do you still get no errors?  If that is the case, then the
> problem must be in how you're processing the imports.  Things must be
> retained in the stylesheet that you are not clearing out.  I don't know
> how you can dynamically import and unimport reliably.
>
There is no difference between <xsl:import> and setImports() because both
are handled by one method.
After processing to html i do sheet.getImports().clear();
So i caught problem with variables. In second xsl variable path is defined
with default value for some pages but in the other this variable is
re-defined with new value exported from xml. But actually this variable is
derived from second xsl with their default value. May be i need to
restructure our site. I don't know

> Can you just make one stylesheet and select the appropriate templates
> somehow or are the imported stylesheets so big that you don't want to
> process them all at once?

No cause structure of our site. There are too many pages to make one.


Re: ElemAttribute

Posted by Gary L Peskin <ga...@firstech.com>.
"Sergey S. Kljopov" wrote:
> Hi!
> It's hard to check cause structure of my xsl's... first.xsl is import
> second.xsl which is import third.xsl. All of them are import corresponding
> xxx_loc.xsl. After all first.xsl is processed with xml.
> So... command line utility warns nothing. %-\
> I must use setImports to improve performance and reduce memory usage.

Sergey --

If you hardcode the xsl:import elements into the stylesheets just for
the test, do you still get no errors?  If that is the case, then the
problem must be in how you're processing the imports.  Things must be
retained in the stylesheet that you are not clearing out.  I don't know
how you can dynamically import and unimport reliably.

Can you just make one stylesheet and select the appropriate templates
somehow or are the imported stylesheets so big that you don't want to
process them all at once?

Gary

Re: ElemAttribute

Posted by "Sergey S. Kljopov" <kl...@wetellyou.com>.
Hi!
It's hard to check cause structure of my xsl's... first.xsl is import
second.xsl which is import third.xsl. All of them are import corresponding
xxx_loc.xsl. After all first.xsl is processed with xml.
So... command line utility warns nothing. %-\
I must use setImports to improve performance and reduce memory usage.

----- Original Message -----
From: "Gary L Peskin" <ga...@firstech.com>
To: <xa...@xml.apache.org>
Sent: Thursday, October 26, 2000 1:03 PM
Subject: Re: ElemAttribute


> > "Sergey S. Kljopov" wrote:
> >
> > Good day.
> >
> > Mm, ok, following is the part pf my xsl. Some confidential
> > and optional information skipped. :)
> >
>
> Hi, Sergey.  This looks fine to me.  Can you run the full example from
> the command line and see if it fails there?
>
> Unfortunately, without a complete stylesheet and input document that can
> recreate the problem, there's not much that I can do.
>
> Gary
>


Re: ElemAttribute

Posted by Gary L Peskin <ga...@firstech.com>.
> "Sergey S. Kljopov" wrote:
> 
> Good day.
> 
> Mm, ok, following is the part pf my xsl. Some confidential
> and optional information skipped. :)
> 

Hi, Sergey.  This looks fine to me.  Can you run the full example from
the command line and see if it fails there?

Unfortunately, without a complete stylesheet and input document that can
recreate the problem, there's not much that I can do.

Gary

Re: ElemAttribute

Posted by "Sergey S. Kljopov" <kl...@wetellyou.com>.
Good day.

Mm, ok, following is the part pf my xsl. Some confidential and optional information skipped. :)

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="LINKS"><xsl:call-template name="LOC0"/></xsl:template>
<xsl:template name="show_users">
  <xsl:choose>
        <xsl:when test="number(@USERS)&gt;0">
            <a class="cute3" style="text-decoration:none">
                <xsl:attribute name="href">?cmd=showSomePage&amp;id=<xsl:value-of select="@ID"/>
                 <font color="red"><xsl:call-template name="LOC3"/></font>
            </a>
        </xsl:when>
        <xsl:when test="@ID=/ROOT/USER/@UID">
          <font class="text"><xsl:call-template name="LOC4"/></font>
        </xsl:when>
        <xsl:otherwise>
              <a class="cute3" style="text-decoration:none">
                <xsl:attribute name="href">?cmd=showOtherPage&amp;oid=<xsl:value-of select="@OID"/></xsl:attribute>
                <font color="red"><xsl:call-template name="LOC3"/></font>
            </a>
          </xsl:otherwise>
      </xsl:choose>

And so on...
This xsl is imported to the other xsl:
                            <!--####################################### Users ################################-->
                            <td width="18%">
                              <img src="{$imagepath}trans.gif" width="5"/>
                              <xsl:choose>
[skipped]
                                      </font>
                                    </xsl:when>
                                    <xsl:otherwise>
<!-- -->                              <xsl:call-template name="show_rating"/> <!-- here is -->
                                    </xsl:otherwise>
                                  </xsl:choose>
                                </xsl:otherwise>
                              </xsl:choose>
                            </td>
                            <!--####################################### END Users ################################-->


----- Original Message ----- 
From: "Gary L Peskin" <ga...@firstech.com>
To: <xa...@xml.apache.org>
Sent: Thursday, October 26, 2000 12:22 PM
Subject: Re: ElemAttribute


> > "Sergey S. Kljopov" wrote:
> > > What do your input xml and stylesheet look like?
> > 
> > xsl:
> > <xsl:template name="PAGE">
> >     <xsl:attribute name="href">?cmd=showPage&amp;id=<xsl:value-of
> > select="@ID"/></xsl:attribute>
> > </xsl:template>
> > 
> > xml:
> > <ROOT>
> >     <PAGE ID="10"/>
> > </ROOT>
> 
> Sergey --
> 
> Okay.  I see what's going on now.  First of all, I didn't see the
> "Illegal attribute name:" because the comment in the ElemAttribute code
> doesn't match the actual text of the message.  I apologize.
> 
> The xsl:attribute element is used to add attributes to result elements
> (XSLT Section 7.1.3).  According to the spec, it is an error to attempt
> to add an attribute to a node that is not an element.  In other words,
> the xsl:attribute element must always be preceded by a result element. 
> This can be either a literal result element or an xsl:element
> instruction.  The xsl:attribute adds an attribute to the preceding
> element.  In your case, there is no preceding element which is why
> you're getting the error message that you are.  I'm not sure what you
> expected the output XML to look like.  If you show that to us, perhaps
> we can propose a stylesheet.
> 
> This error should be reported by both engines.  The namespace attribute
> that I was referring to was the namespace attribute of the xsl:attribute
> element which allows you to generate an attribute with a namespace as
> part of the full attribute name.  You haven't specified that, which is
> fine.
> 
> > So, back to setImports(): i add to the
> > org.apache.xalan.xslt.ElemCallTemplate.execute() line m_template =
> > null; to cleanup all stored previous templates. So when
> > StylesheetHandler tries to call template it tries to find out new
> > templates. Is this ok?
> 
> On the setImports() thing, I have to caution you again that I'm not that
> familiar with the ins and outs of xsl:import processing and that this
> changes substantially in XalanJ2.  As far as I know, it was not
> contemplated that you would be dynamically adding and subtracting
> imports from importing stylesheets by calling setImports() and
> manipulating fields inside ElemCallTemplate.  I'd give you the answer if
> I knew it but I just don't.
> 
> I think you're far better off having two stylesheets with the different
> import elements or importing both imported stylesheets and controlling
> template selection some other way.  This depends on your application. 
> But calling unsupported interfaces, which are subject to change at any
> time, is probably not a good thing if you want some stability.
> 
> Gary
> 

Re: ElemAttribute

Posted by Gary L Peskin <ga...@firstech.com>.
> "Sergey S. Kljopov" wrote:
> > What do your input xml and stylesheet look like?
> 
> xsl:
> <xsl:template name="PAGE">
>     <xsl:attribute name="href">?cmd=showPage&amp;id=<xsl:value-of
> select="@ID"/></xsl:attribute>
> </xsl:template>
> 
> xml:
> <ROOT>
>     <PAGE ID="10"/>
> </ROOT>

Sergey --

Okay.  I see what's going on now.  First of all, I didn't see the
"Illegal attribute name:" because the comment in the ElemAttribute code
doesn't match the actual text of the message.  I apologize.

The xsl:attribute element is used to add attributes to result elements
(XSLT Section 7.1.3).  According to the spec, it is an error to attempt
to add an attribute to a node that is not an element.  In other words,
the xsl:attribute element must always be preceded by a result element. 
This can be either a literal result element or an xsl:element
instruction.  The xsl:attribute adds an attribute to the preceding
element.  In your case, there is no preceding element which is why
you're getting the error message that you are.  I'm not sure what you
expected the output XML to look like.  If you show that to us, perhaps
we can propose a stylesheet.

This error should be reported by both engines.  The namespace attribute
that I was referring to was the namespace attribute of the xsl:attribute
element which allows you to generate an attribute with a namespace as
part of the full attribute name.  You haven't specified that, which is
fine.

> So, back to setImports(): i add to the
> org.apache.xalan.xslt.ElemCallTemplate.execute() line m_template =
> null; to cleanup all stored previous templates. So when
> StylesheetHandler tries to call template it tries to find out new
> templates. Is this ok?

On the setImports() thing, I have to caution you again that I'm not that
familiar with the ins and outs of xsl:import processing and that this
changes substantially in XalanJ2.  As far as I know, it was not
contemplated that you would be dynamically adding and subtracting
imports from importing stylesheets by calling setImports() and
manipulating fields inside ElemCallTemplate.  I'd give you the answer if
I knew it but I just don't.

I think you're far better off having two stylesheets with the different
import elements or importing both imported stylesheets and controlling
template selection some other way.  This depends on your application. 
But calling unsupported interfaces, which are subject to change at any
time, is probably not a good thing if you want some stability.

Gary

Re: ElemAttribute

Posted by "Sergey S. Kljopov" <kl...@wetellyou.com>.
Good day, Gary

> I'm really confused by your message.  Both engines should work the
So am i :)
> same.  You haven't specified the namespace attribute in your
I have specified the namespace in tag <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

> xsl:attribute element so you should never even encounter the 2nd if.  As
> long as you have an element pending, you should always drop into the 1st
> else.
Which happened. But on apache i receive xsl warning extra. So i comment those else simply because i drop into the 3rd if anyway.
> 
> You say you're getting the message "Illegal attribute name" but I don't
> see that issued anywhere from the code you indicate.
This message is declared in the 2nd else:
processor.warn(XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_NAME, new Object[]{origAttrName});

> 
> What do your input xml and stylesheet look like? 

xsl:
<xsl:template name="PAGE">
    <xsl:attribute name="href">?cmd=showPage&amp;id=<xsl:value-of select="@ID"/></xsl:attribute>
</xsl:template>

xml:
<ROOT>
    <PAGE ID="10"/>
</ROOT>

> you run this from the command line?
No.

So, back to setImports(): i add to the org.apache.xalan.xslt.ElemCallTemplate.execute() line m_template = null; to cleanup all stored previous templates. So when StylesheetHandler tries to call template it tries to find out new templates. Is this ok?

WBR, Sergey S. Kljopov

Re: ElemAttribute

Posted by Gary L Peskin <ga...@firstech.com>.
> "Sergey S. Kljopov" wrote:
> I have a xsl file with tag <xsl:attribite name="href">. So attrName ==
> "href".
> Apache JServ gives me XSL Warning: Illegal attribute name: href
> Let me look through this code. At first, i'm fall into the 1st if
> block because attrName == "href", not null. At second i pass the 2nd
> if block because attrNameSpace for my attrName == null. Than... at
> Apache JServ i'm fall into the 2nd else so i can see XSL Warning, but
> if i test my processor and xsl locally on the JBuilder's servlet
> engine i do not receive this warning because i'm fall into the 1st
> else block (this is checked) and into the 3rd if block after all
> (because indexOfNSSep which is ':' == -1)
> Why i receive warning on apache and is this bad warning? Can i switch
> off this else simply?

Sergey --

I'm really confused by your message.  Both engines should work the
same.  You haven't specified the namespace attribute in your
xsl:attribute element so you should never even encounter the 2nd if.  As
long as you have an element pending, you should always drop into the 1st
else.

You say you're getting the message "Illegal attribute name" but I don't
see that issued anywhere from the code you indicate.

What do your input xml and stylesheet look like?  Do you get errors when
you run this from the command line?

Gary