Question

I have a DITA bookmap where I am storing image paths:

<bookmap>
    <bookmeta>
        <data id="productLogo">
            <image href="images/_notrans/frontcover/productLogo.svg" />
        </data>
        <data id="productPhoto" >
            <image href="images/_notrans/frontcover/productPhoto.jpg" />
        </data>
    </bookmeta>
</bookmap>

Then I attempt to grab the href values by data[@id]:

<xsl:variable name="productLogo"><xsl:value-of select="//data[@id='productLogo']/image/@href" /></xsl:variable>
<xsl:variable name="productPhoto"><xsl:value-of select="//data[@id='productPhoto']/image/@href" /></xsl:variable> 

(These XPath expressions match the href when I test against my bookmap in Oxygen.)

During transformation I output:

<xsl:message>productPhoto: <xsl:value-of select="$productPhoto"/></xsl:message>

The value-of is always empty.

However, everything works as expected if I replace the id attribute with numbers:

<xsl:variable name="productLogo"><xsl:value-of select="//data[1]/image/@href" /></xsl:variable>
<xsl:variable name="productPhoto"><xsl:value-of select="//data[2]/image/@href" /></xsl:variable> 

What am I doing wrong that's preventing using @id="whatever"?

Was it helpful?

Solution

The XSLT is not applied directly over the Bookmap contents, it is applied over an XML document which contains the bookmap with all topic references expanded in it and with some preprocessing applied to it. If you set the "clean.temp" parameter to "no" you will find in the temporary files folder a file called something like "mapName_MERGED.xml", that is the XML document over which the XSLT is applied and as you will see in it, all IDs have been changed to be unique in the context of the entire XML document.

When usually working with data elements you should set the @name attribute to them like:

<data name="productLogo">

and match that name in the XSLT code. There are examples of using "data" in the DITA 1.2 specs as well:

http://docs.oasis-open.org/dita/v1.2/os/spec/langref/data.html#data

OTHER TIPS

Another option, depending on your needs, is to develop a naming convention for the product photos and use the element to build the URI. As the product logo shouldn't change for a product family, it wouldn't hurt to hard-code that in the XSLT code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top