0
votes

I want to create a dynamic XSLT Variable. It should fetch the content of the first td of each row, something like this:

<tr><td>1</td><td>not Important</td></tr>
<tr><td>2</td><td>not Important</td></tr>
<tr><td>3</td><td>not Important</td></tr>

My XSL:Variable looks something like this:

<xsl:variable name="name" select="concat('out/',//td[1]/text(),'.html')"/>

I want to use the elements content (in my Case 1, 2, 3) to create new Html Files and name them accordingly:

<xsl:result-document href="{$name}">

Result: 1.html 2.html 3.html

With my current XSL:Variable Oxygen would give me that error: A sequence of more than one item is not allowed as the second argument of concat()

2

2 Answers

0
votes

If you want to map each row to a result document then I suggest to write a template

<xsl:template match="tr"> <xsl:result-document href="out{td[1]}.html"> ... </xsl:result-document> </xsl:template>

then make sure there is an apply-templates for the parent table that makes sure the tr elementd are processed.

0
votes

The problem you got there is, that the concat()-function can put strings together, but your statement "//td[1]/text" does indeed select 3 strings, not just one.

A way to generate these 3 filenames would be iterating over the tr-nodes and selecting the first td-node in each of them:

<xsl:for-each select="//tr">
    <xsl:variable name="justOneNameAtATime"
        select="concat('out/',.//td[1]/text(),'.html')" />
    <!-- do whatever you want with the single name, e.g.: -->
    <xsl:result-document href="{$name}">
</xsl:for-each>

Notice the dot in front of the "//", meaning that the search for "td"-nodes will only take place in the current context (= in the "tr"-node).