Adding Text to Elements

What we have seen on Figure 1 is almost unusable in real document authoring, because one can see no text in ContentMap items. Let`s resolve this problem.

See example ContentMap Items With Text.

Figure 1. Text In ContentMap Items



ContentMap Items With Text

In following stylesheet we add csl:collect-text instruction that will show text content of the matched element. Note that select attribute is present and set to " text()". This will cause collecting text only from this element but not from all its descendants.

But that`s not all. We insert csl:when-closed instruction to our template. Now when we close item (click little "minus" sign beside the ContentMap item), its text will be collected using child instructions of csl:when-closed.

The only instruction of csl:when-closed is csl:collect-text without attributes. Such instruction collects all the text from element subtree. This text will show up in gray color. See how it looks at Figure 1

<?xml version='1.0'?>

<csl:stylesheet xmlns:csl="http://www.syntext.com/Extensions/CSL-1.0">



    <csl:template match="*">

        <csl:collect-text select="text()"/>

        <csl:when-closed>        

            <csl:collect-text/>

        </csl:when-closed>

    </csl:template>



</csl:stylesheet>