help with xpath

T

T

Hi, I'm trying to get the alt text from this bit of docbook xml:
<inlineequation>
<inlinemediaobject remap="math">
<alt>$F$</alt>
<imageobject>
<imagedata depth="0px"
fileref="images/geneug_whatsnew0001.png"
contentwidth="10px" contentdepth="10px" role="math" />
</imageobject>
</inlinemediaobject>
</inlineequation>

With this selector:
<xsl:template match="d:inlineequation/d:inlinemediaobject/
d:imageobject/d:imagedata[@depth]">
<xsl:element name="img">
<xsl:attribute name="alt"><xsl:value-of select="../../alt"/></
xsl:attribute>
etc....

In my Xpath visualizer the path looks right:
//inlineequation/inlinemediaobject/imageobject/imagedata[@depth]/../../
alt

but my stylesheet never renders the alt text. When I use the selector
in the xsl:template using the [@depth] attribute, is the attribute or
the element selected?

Just trying to figure out what is going on.
thanks,
--Tim Arnold
 
M

Martin Honnen

T said:
Hi, I'm trying to get the alt text from this bit of docbook xml:
<inlineequation>
<inlinemediaobject remap="math">
<alt>$F$</alt>
<imageobject>
<imagedata depth="0px"
fileref="images/geneug_whatsnew0001.png"
contentwidth="10px" contentdepth="10px" role="math" />
</imageobject>
</inlinemediaobject>
</inlineequation>

With this selector:
<xsl:template match="d:inlineequation/d:inlinemediaobject/
d:imageobject/d:imagedata[@depth]">
<xsl:element name="img">
<xsl:attribute name="alt"><xsl:value-of select="../../alt"/></
xsl:attribute>

The use of the 'd' prefix on the other elements suggests a namespace
applies so you want
../../d:alt

Also note that your code is rather verbose, literal result elements and
attribute value templates are shorter e.g.
<img alt="{../../d:alt}" />
 
T

T

T said:
Hi, I'm trying to get the alt text from this bit of docbook xml:
<inlineequation>
<inlinemediaobject remap="math">
<alt>$F$</alt>
<imageobject>
  <imagedata depth="0px"
      fileref="images/geneug_whatsnew0001.png"
      contentwidth="10px" contentdepth="10px" role="math" />
</imageobject>
</inlinemediaobject>
</inlineequation>
With this selector:
<xsl:template match="d:inlineequation/d:inlinemediaobject/
d:imageobject/d:imagedata[@depth]">
  <xsl:element name="img">
    <xsl:attribute name="alt"><xsl:value-of select="../../alt"/></
xsl:attribute>

The use of the 'd' prefix on the other elements suggests a namespace
applies so you want
   ../../d:alt

Also note that your code is rather verbose, literal result elements and
attribute value templates are shorter e.g.
   <img alt="{../../d:alt}" />

Hi Martin,
I am getting old and forgetful. Thanks for pointing out I had omitted
the namespace abbreviation. That was the problem of course...

Thanks also for the comment about the verbosity. I did not know I
could use such a simple syntax. The books I have on XSLt show the
verbose method, which is where I learned it. However, the stylesheet
fragment I posted is for creating HTML 4.0 instead of XHTML; I think
that means I must use the verbose method, correct? (since <img ... />
is illegal in HTML 4.)

thanks for your help,
--Tim Arnold
 
M

Martin Honnen

T said:
Thanks also for the comment about the verbosity. I did not know I
could use such a simple syntax. The books I have on XSLt show the
verbose method, which is where I learned it. However, the stylesheet
fragment I posted is for creating HTML 4.0 instead of XHTML; I think
that means I must use the verbose method, correct? (since <img ... />
is illegal in HTML 4.)

No, the stylesheet creates a result tree which is then optionally
serialized according to the rules of the output method and that way,
whether you use
<xsl:element name="img"/>
or
<img/>
that simply creates an "img" element in the result tree and when that is
serialized with output method="html" the serialization takes care of
outputting
<img>
according to HTML rules.
 
T

T

No, the stylesheet creates a result tree which is then optionally
serialized according to the rules of the output method and that way,
whether you use
   <xsl:element name="img"/>
or
   <img/>
that simply creates an "img" element in the result tree and when that is
serialized with output method="html" the serialization takes care of
outputting
   <img>
according to HTML rules.

Wow, thanks for that information. I'll start changing my coding now--
it's much easier to understand the way you wrote it.

thanks again,
--Tim Arnold
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top