You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Jose Correia <jo...@exinet.co.za> on 2000/05/31 13:10:37 UTC

testing attribute value

Hi guys

I need to know something pretty urgently:

Is there a way to specify inside the xsl file, that if an attribute of an
element is not specified in the source file, then I musn't include it in the
output file.

e.g. Given this line in the source file:
<img src="flood1.gif" hspace="3" vspace="5" align="right" />

and this bit of the xsl file:

<xsl:attribute-set name="img-attributes">
  <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
  <xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute>
  <xsl:attribute name="style"><xsl:value-of select="@style"/></xsl:attribute>
  <xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute>
  <xsl:attribute name="xml:lang"><xsl:value-of
select="@xml:lang"/></xsl:attribute>
  <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
  <xsl:attribute name="border"><xsl:value-of select="@border"/></xsl:attribute>
  <xsl:attribute name="hspace"><xsl:value-of select="@hspace"/></xsl:attribute>
  <xsl:attribute name="vspace"><xsl:value-of select="@vspace"/></xsl:attribute>
  <xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
  <xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
  <xsl:attribute name="longdesc"><xsl:value-of
select="@longdesc"/></xsl:attribute>
  <xsl:attribute name="height"><xsl:value-of select="@height"/></xsl:attribute>
  <xsl:attribute name="width"><xsl:value-of select="@width"/></xsl:attribute>
  <xsl:attribute name="usemap"><xsl:value-of select="@usemap"/></xsl:attribute>
</xsl:attribute-set>
<xsl:template match ="img">
  <img xmlns:html="http://www.w3.org/TR/REC-html40"
xsl:use-attribute-sets="img-attributes">
  <xsl:apply-templates/>
  </img>
</xsl:template>

If I run this the output will be something like:
<img id="" class="" style="" title="" xml:lang="" align="right" border=""
hspace="3" vspace="5" src="flood1.gif" alt="" longdesc="" height="" width=""
usemap=""/>

Is there a way such that only the attributes in the src file will get copied
over? You might ask yourselves why not just copy it over but these elements I
need to convert are a subset of a bigger set.

Thanks in advance
Jose Correia


Scott Boag/CAM/Lotus wrote:

> Thanks, I'll try and look into these tomorrow.  In the latest CVS I put in
> some defensive protection for the stack miss-pop.  The variable ref
> out-of-context dumps are more worrisome.  But I have another bug on my
> queue from someone else that I think is the same thing, so hopefully I will
> get to the bottom of this soon!
>
> -scott
>
>
>                     Christoph
>                     Oehler               To:     xalan-dev@xml.apache.org
>                     <coehler@iiic        cc:     (bcc: Scott Boag/CAM/Lotus)
>                     .ethz.ch>            Subject:     Emptystack exception
>
>                     05/31/2000
>                     04:09 AM
>                     Please
>                     respond to
>                     xalan-dev
>
>
>
> Hi Scott
>
> >
> >Christoph Oehler <co...@iiic.ethz.ch> wrote:
> >> We're using Cocoon 1.7.2, Sun XML Parser 2 and Xalan 1.0.1. We're
> getting
> >> several unreproducable errors:
> >
> >Christoph, is there a sample XML and stylesheet you could give me to try
> >and reproduce this problem (I understand the errors seem to be
> >unreproducable, but at least it's a start...).
> >
> >-scott
>
> Here are two sample files plus a stacktrace. It is really strange, cause
> most of the time it works just fine!!!
>
> Thanks a lot
> Christoph

--

                \=/,         _-===-_-===-_-===-_-===-_-==-_
                |  @___oo  (                               )_
      /\  /\   / (___,,,}_--=                                )
     ) /^\) ^\/ _)        =_"Positive thinking - a great way  )
     )   /^\/   _)         (_        to face life"             )
     )   _ /  / _)          (        Jose Correia            )
 /\  )/\/ ||  | )_)          (_    jose@exinet.co.za        )
<  >      |(,,) )__)           (   jcorreia@global.co.za    )
 ||      /    \)___)\           (_                        _)
 | \____(      )___) )___          -==-_______-=====-___==
  \______(_______;;; __;;;



Re: testing attribute value

Posted by Jose Correia <jo...@exinet.co.za>.
Ok, but how do then I add this attribute to attribute-set? I tried:

<xsl:attribute-set name=img-attributes\">
<xsl:if test="@id">
  <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
</xsl:if>
<xsl:attribute-set>

But the processor does not like it:
"ElemTemplateElement error: Can not add xsl:if to xsl:attribute-set"

Any other ideas

Thanks
Jose

Christoph Oehler wrote:

> There is a way .. use <xsl:if test=""></xsl:if>
>
> for example:
>
> <xsl:if test="@id">
>   <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
> </xsl:if>
>
> Greetings
> Christoph
>
> Am/Um 13:10 31.05.2000 +0200 schrieben Sie:
> >Hi guys
> >
> >I need to know something pretty urgently:
> >
> >Is there a way to specify inside the xsl file, that if an attribute of an
> >element is not specified in the source file, then I musn't include it in the
> >output file.
> >
> >e.g. Given this line in the source file:
> ><img src="flood1.gif" hspace="3" vspace="5" align="right" />
> >
> >and this bit of the xsl file:
> >
> ><xsl:attribute-set name="img-attributes">
> >  <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
> >  <xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute>
> >  <xsl:attribute name="style"><xsl:value-of select="@style"/></xsl:attribute>
> >  <xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute>
> >  <xsl:attribute name="xml:lang"><xsl:value-of
> >select="@xml:lang"/></xsl:attribute>
> >  <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
> >  <xsl:attribute name="border"><xsl:value-of
> select="@border"/></xsl:attribute>
> >  <xsl:attribute name="hspace"><xsl:value-of
> select="@hspace"/></xsl:attribute>
> >  <xsl:attribute name="vspace"><xsl:value-of
> select="@vspace"/></xsl:attribute>
> >  <xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
> >  <xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
> >  <xsl:attribute name="longdesc"><xsl:value-of
> >select="@longdesc"/></xsl:attribute>
> >  <xsl:attribute name="height"><xsl:value-of
> select="@height"/></xsl:attribute>
> >  <xsl:attribute name="width"><xsl:value-of select="@width"/></xsl:attribute>
> >  <xsl:attribute name="usemap"><xsl:value-of
> select="@usemap"/></xsl:attribute>
> ></xsl:attribute-set>
> ><xsl:template match ="img">
> >  <img xmlns:html="http://www.w3.org/TR/REC-html40"
> >xsl:use-attribute-sets="img-attributes">
> >  <xsl:apply-templates/>
> >  </img>
> ></xsl:template>
> >
> >If I run this the output will be something like:
> ><img id="" class="" style="" title="" xml:lang="" align="right" border=""
> >hspace="3" vspace="5" src="flood1.gif" alt="" longdesc="" height="" width=""
> >usemap=""/>
> >
> >Is there a way such that only the attributes in the src file will get copied
> >over? You might ask yourselves why not just copy it over but these elements I
> >need to convert are a subset of a bigger set.
> >
> >Thanks in advance
> >Jose Correia
> >
> >
> >Scott Boag/CAM/Lotus wrote:
> >
> >> Thanks, I'll try and look into these tomorrow.  In the latest CVS I put in
> >> some defensive protection for the stack miss-pop.  The variable ref
> >> out-of-context dumps are more worrisome.  But I have another bug on my
> >> queue from someone else that I think is the same thing, so hopefully I will
> >> get to the bottom of this soon!
> >>
> >> -scott
> >>
> >>
> >>                     Christoph
> >>                     Oehler               To:     xalan-dev@xml.apache.org
> >>                     <coehler@iiic        cc:     (bcc: Scott
> Boag/CAM/Lotus)
> >>                     .ethz.ch>            Subject:     Emptystack exception
> >>
> >>                     05/31/2000
> >>                     04:09 AM
> >>                     Please
> >>                     respond to
> >>                     xalan-dev
> >>
> >>
> >>
> >> Hi Scott
> >>
> >> >
> >> >Christoph Oehler <co...@iiic.ethz.ch> wrote:
> >> >> We're using Cocoon 1.7.2, Sun XML Parser 2 and Xalan 1.0.1. We're
> >> getting
> >> >> several unreproducable errors:
> >> >
> >> >Christoph, is there a sample XML and stylesheet you could give me to try
> >> >and reproduce this problem (I understand the errors seem to be
> >> >unreproducable, but at least it's a start...).
> >> >
> >> >-scott
> >>
> >> Here are two sample files plus a stacktrace. It is really strange, cause
> >> most of the time it works just fine!!!
> >>
> >> Thanks a lot
> >> Christoph
> >
> >--
> >
> >                \=/,         _-===-_-===-_-===-_-===-_-==-_
> >                |  @___oo  (                               )_
> >      /\  /\   / (___,,,}_--=                                )
> >     ) /^\) ^\/ _)        =_"Positive thinking - a great way  )
> >     )   /^\/   _)         (_        to face life"             )
> >     )   _ /  / _)          (        Jose Correia            )
> > /\  )/\/ ||  | )_)          (_    jose@exinet.co.za        )
> ><  >      |(,,) )__)           (   jcorreia@global.co.za    )
> > ||      /    \)___)\           (_                        _)
> > | \____(      )___) )___          -==-_______-=====-___==
> >  \______(_______;;; __;;;
> >
> >
> >
> >

--

                \=/,         _-===-_-===-_-===-_-===-_-==-_
                |  @___oo  (                               )_
      /\  /\   / (___,,,}_--=                                )
     ) /^\) ^\/ _)        =_"Positive thinking - a great way  )
     )   /^\/   _)         (_        to face life"             )
     )   _ /  / _)          (        Jose Correia            )
 /\  )/\/ ||  | )_)          (_    jose@exinet.co.za        )
<  >      |(,,) )__)           (   jcorreia@global.co.za    )
 ||      /    \)___)\           (_                        _)
 | \____(      )___) )___          -==-_______-=====-___==
  \______(_______;;; __;;;



Re: testing attribute value

Posted by Christoph Oehler <co...@iiic.ethz.ch>.
There is a way .. use <xsl:if test=""></xsl:if>

for example:

<xsl:if test="@id">
  <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
</xsl:if>

Greetings
Christoph



Am/Um 13:10 31.05.2000 +0200 schrieben Sie:
>Hi guys
>
>I need to know something pretty urgently:
>
>Is there a way to specify inside the xsl file, that if an attribute of an
>element is not specified in the source file, then I musn't include it in the
>output file.
>
>e.g. Given this line in the source file:
><img src="flood1.gif" hspace="3" vspace="5" align="right" />
>
>and this bit of the xsl file:
>
><xsl:attribute-set name="img-attributes">
>  <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
>  <xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute>
>  <xsl:attribute name="style"><xsl:value-of select="@style"/></xsl:attribute>
>  <xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute>
>  <xsl:attribute name="xml:lang"><xsl:value-of
>select="@xml:lang"/></xsl:attribute>
>  <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
>  <xsl:attribute name="border"><xsl:value-of
select="@border"/></xsl:attribute>
>  <xsl:attribute name="hspace"><xsl:value-of
select="@hspace"/></xsl:attribute>
>  <xsl:attribute name="vspace"><xsl:value-of
select="@vspace"/></xsl:attribute>
>  <xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
>  <xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute>
>  <xsl:attribute name="longdesc"><xsl:value-of
>select="@longdesc"/></xsl:attribute>
>  <xsl:attribute name="height"><xsl:value-of
select="@height"/></xsl:attribute>
>  <xsl:attribute name="width"><xsl:value-of select="@width"/></xsl:attribute>
>  <xsl:attribute name="usemap"><xsl:value-of
select="@usemap"/></xsl:attribute>
></xsl:attribute-set>
><xsl:template match ="img">
>  <img xmlns:html="http://www.w3.org/TR/REC-html40"
>xsl:use-attribute-sets="img-attributes">
>  <xsl:apply-templates/>
>  </img>
></xsl:template>
>
>If I run this the output will be something like:
><img id="" class="" style="" title="" xml:lang="" align="right" border=""
>hspace="3" vspace="5" src="flood1.gif" alt="" longdesc="" height="" width=""
>usemap=""/>
>
>Is there a way such that only the attributes in the src file will get copied
>over? You might ask yourselves why not just copy it over but these elements I
>need to convert are a subset of a bigger set.
>
>Thanks in advance
>Jose Correia
>
>
>Scott Boag/CAM/Lotus wrote:
>
>> Thanks, I'll try and look into these tomorrow.  In the latest CVS I put in
>> some defensive protection for the stack miss-pop.  The variable ref
>> out-of-context dumps are more worrisome.  But I have another bug on my
>> queue from someone else that I think is the same thing, so hopefully I will
>> get to the bottom of this soon!
>>
>> -scott
>>
>>
>>                     Christoph
>>                     Oehler               To:     xalan-dev@xml.apache.org
>>                     <coehler@iiic        cc:     (bcc: Scott
Boag/CAM/Lotus)
>>                     .ethz.ch>            Subject:     Emptystack exception
>>
>>                     05/31/2000
>>                     04:09 AM
>>                     Please
>>                     respond to
>>                     xalan-dev
>>
>>
>>
>> Hi Scott
>>
>> >
>> >Christoph Oehler <co...@iiic.ethz.ch> wrote:
>> >> We're using Cocoon 1.7.2, Sun XML Parser 2 and Xalan 1.0.1. We're
>> getting
>> >> several unreproducable errors:
>> >
>> >Christoph, is there a sample XML and stylesheet you could give me to try
>> >and reproduce this problem (I understand the errors seem to be
>> >unreproducable, but at least it's a start...).
>> >
>> >-scott
>>
>> Here are two sample files plus a stacktrace. It is really strange, cause
>> most of the time it works just fine!!!
>>
>> Thanks a lot
>> Christoph
>
>--
>
>                \=/,         _-===-_-===-_-===-_-===-_-==-_
>                |  @___oo  (                               )_
>      /\  /\   / (___,,,}_--=                                )
>     ) /^\) ^\/ _)        =_"Positive thinking - a great way  )
>     )   /^\/   _)         (_        to face life"             )
>     )   _ /  / _)          (        Jose Correia            )
> /\  )/\/ ||  | )_)          (_    jose@exinet.co.za        )
><  >      |(,,) )__)           (   jcorreia@global.co.za    )
> ||      /    \)___)\           (_                        _)
> | \____(      )___) )___          -==-_______-=====-___==
>  \______(_______;;; __;;;
>
>
>
>