Question

I am parsing some DocBook xml to convert to our internal format.

In processing a tgroup element like the following:

      <tgroup cols="4">
        <colspec colwidth="1*" />
        <colspec colwidth="1*" />
        <colspec colwidth="1*" />
        <colspec colwidth="1*" />

If a given tgroup's col attribute value matches exactly the number of child colspec elements AND there is a colwidth attribute for that colspec, i want to use the colwidth value in the colspec element in the result tree.

My check and the code is as follows:

<xsl:when test="(@cols = count(./colspec)) and (./colspec[@colwidth][$number])">

   <colspec>
      <xsl:attribute name="colnum">
           <xsl:value-of select="$number"/>
  </xsl:attribute>
  <xsl:attribute name="colname">
       <xsl:value-of select="$number"/>
  </xsl:attribute>


  <xsl:attribute name="colwidth">
       <xsl:value-of select="./colspec[@colwidth][$number]"/>
  </xsl:attribute>
</colspec>

($number is the number of the current colspec being processed.) Instead of getting the colwidth of 1*, i just get

coldwidth=""

Do i need to specify that i want the attribute value?

I always get kind of tripped up on the xpath expressions, any help any one can provide is greatly appreciated!

Thanks,

Russ

Était-ce utile?

La solution

Jirka is right ... the attribute isn't being addressed.

But to be more maintainable I would have coded it along the lines of:

<xsl:when test="(@cols = count(colspec)) and (colspec[@colwidth][$number])">

  <colspec colnum="{$number}" colname="{$number}" 
           colwidth="{colspec[@colwidth][$number]/@colwidth}"/>
  </colspec>

The use of ./ is redundant and cluttering, and the simple value expressions for attributes can be coded with attribute value templates.

Autres conseils

I think you should use this <xsl:value-of select="./colspec[@colwidth][$number]/@colwidth"/>. I'm not sure but I think attribute values are not part of string value (which is outputted by value-of).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top