0

i need to add an attribute initial-page-number to a tag fo:sequence

tha tag is

<fo:page-sequence master-reference="alternating" initial-page-number="1"><fo:page-sequence>
..
...
</fo:page-sequence>

become

<fo:page-sequence master-reference="alternating" initial-page-number="1">
..
</fo:page-sequence>

but with the xslt i obtain two fo:page:

<fo:page-sequence master-reference="alternating" initial-page-number="1"><fo:page-sequence>
</fo:page-sequence></fo:page-sequence>

How can i replace old fo:page-sequence with new one?

This is my xsl stylesheet:

<xsl:stylesheet>

<xsl:template match="ss:split/fo:page-sequence">
<xsl:choose>
<xsl:when test="@master-reference['alternating']">
    <xsl:element name="fo:page-sequence">
        <xsl:for-each select="@*">
                <xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
        </xsl:for-each>
        <xsl:attribute name="initial-page-number">
            <xsl:value-of select="1"/>
        </xsl:attribute>
        <xsl:copy>
            <xsl:apply-templates select="child::*"/>
        </xsl:copy>
    </xsl:element>
</xsl:when>
</xsl:choose>
</xsl:template>



<xsl:template match='comment()'>
 <xsl:comment><xsl:value-of select="."/></xsl:comment>
</xsl:template>


<xsl:template match="@*|*">
 <xsl:copy>
   <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

</xsl:stylesheet>
robyp7
  • 481
  • 2
  • 7
  • 25

2 Answers2

0

Your stylesheet creates an fo:page-sequence using <xsl:element name="fo:page-sequence">, and another one with <xsl:copy> (as the matching element is an fo:page-sequence).

Just remove the xsl:copy (but leave <xsl:apply-templates select="child::*"/>, as you want to process the children of the current node!) and you should get what you need.

lfurini
  • 3,729
  • 4
  • 30
  • 48
0

Your stylesheet changes every fo:page-sequence because the predicate ['alternating'] is always true.

You can check for the master-reference value in the match pattern, plus you can just copy the existing attributes, and you can copy the contents of the fo:page-sequence since it won't contain another fo:page-sequence:

<xsl:template
      match="ss:split/fo:page-sequence[@master-reference = 'alternating']">
    <xsl:copy>
        <xsl:copy-of select="@*" />
        <xsl:attribute name="initial-page-number">1</xsl:attribute>
        <xsl:copy-of select="node()" />
    </xsl:copy>
</xsl:template>
Tony Graham
  • 7,306
  • 13
  • 20