Vladislav Ivanov
Vladislav Ivanov

Reputation: 229

dita-ot: is it possible to create a new element which would transform into a set of existing elements?

I'm using dita-ot 2.4. I need to add a new element into my document. It's supposed to be transformed into a set of different elements through XSL transformations. I have created a plugin which defines a new element and its attributes, and adds it into existing topic template. I have also added some basic XSL processing into an output processing plugin:

<xsl:attribute-set name="rootelement">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:attribute-set>

<xsl:template match="rootelement">
    <fo:inline xsl:use-attribute-sets="rootelement">
        <xsl:call-template name="commonattributes"/>
        <xsl:apply-templates/>
    </fo:inline>
</xsl:template>

So, now I can write the following in my document and it will appear in bold (in PDF):

<rootelement>
    test
</rootelement>

However, what I was initially aiming for is to create a transformation for <rootelement> which would emit other elements, for example, like this:

<xsl:template match="rootelement">
    <b>Some text:</b>
    <xsl:value-of select="current()" />
    <i>Some other text</i>
</xsl:template>

The actual transformation is a bit more complex and involves tables, so I can't just apply display attributes to this element.

Is it possible to implement such behaviour in DITA? Do I need specialization at all?

Edit: to clarify, here is a piece of stylesheet that seems to work:

<xsl:template match="rootelement">
    <xsl:text>
        Text:
    </xsl:text>
    <fo:inline xsl:use-attribute-sets="rootelement">
        <xsl:call-template name="commonattributes"/>
        <xsl:apply-templates/>
    </fo:inline>
</xsl:template>

Every instance of rootelement is prepended with "Text: ".

This stylesheet, on the other hand, does not produce expected results:

<xsl:template match="rootelement">
    <i>
        <xsl:text>
            Text:
        </xsl:text>
    </i>
    <fo:inline xsl:use-attribute-sets="rootelement">
        <xsl:call-template name="commonattributes"/>
        <xsl:apply-templates/>
    </fo:inline>
</xsl:template>

The "Text: " part instead of being printed in italics just disappears. Moreover, just putting <rootelement><i>Text: </i> some text</rootelement> in the source XML works as expected.

Upvotes: 0

Views: 150

Answers (1)

JulioV
JulioV

Reputation: 516

You do need to use specialization to implement . You should be able to use the template match to create an and its children to place the content you want in the output stream. Your samples have the basics of what you need from the XSLT side; you just need to work through the table structure to define what you need.

Upvotes: 0

Related Questions