XSL:FO Different list-item-label per level - xslt

I'm using Apache FOP to generate PDFs from my web application, where users can edit richtext using CKEditor.
My problem is that users sometimes use different levels of indentation in (un-)ordered lists, e.g.:
List item level 1
List item level 2
The CKEditor shows different bulletins per level (or indentation), but the generated PDFs do not, because my template looks like this:
<!-- Lists -->
<xsl:template match="ul|ol" mode="content">
<xsl:apply-templates select="li" mode="content">
<xsl:with-param name="ordered">
<xsl:value-of select="name()='ol'"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="li" mode="content">
<xsl:param name="ordered"/>
<xsl:variable name="label">
<xsl:choose>
<xsl:when test="$ordered='true'">
<xsl:value-of select="position()"/>
.
</xsl:when>
<xsl:otherwise>
•
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<fo:list-block padding-bottom="0pt">
<fo:list-item>
<fo:list-item-label>
<fo:block>
<xsl:value-of select="$label"/>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates mode="content"/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>
So how can I set the label variable depending on which level of indentation I'm at?
Something like:
1st level: &#8226
2nd level: &#9702
3rd level: &#8269
Thanks in advance, ~Fabi
EDIT: So the solution suggested by #fafl looks like this:
<!-- Lists -->
<xsl:template match="ul|ol" mode="content">
<xsl:param name="depth" select="0"/>
<xsl:apply-templates select="li" mode="content">
<xsl:with-param name="ordered">
<xsl:value-of select="name()='ol'"/>
</xsl:with-param>
<xsl:with-param name="depth">
<xsl:value-of select="$depth + 1"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="li" mode="content">
<xsl:param name="depth" select="0"/>
<xsl:param name="ordered"/>
<xsl:variable name="label">
<xsl:choose>
<xsl:when test="$ordered='true'">
<xsl:value-of select="position()"/>
.
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$depth = 1">
• <!--filled circle-->
</xsl:when>
<xsl:when test="$depth = 2">
◦ <!--not-filled circle-->
</xsl:when>
<xsl:otherwise>
■ <!--black square -->
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<fo:list-block padding-bottom="0pt">
<fo:list-item>
<fo:list-item-label>
<fo:block>
<xsl:value-of select="$label"/>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates mode="content">
<xsl:with-param name="depth">
<xsl:value-of select="$depth"/>
</xsl:with-param>
</xsl:apply-templates>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>

Try adding a parameter "depth" to both templates with a default value of 1. On each recursive call of "ul|ol" increase it by 1. Then you can query it inside both templates.

Related

Using node-set with Antenna House XSL-FO XSLT

I would like to use node-set() in Antenna House so I can access preceding-siblings in a sorted list. (I'm trying to follow this example: [using preceding-sibling with with xsl:sort)
I'm not sure what the syntax is for declaring the namespace to access node-set(). AH is not giving any errors, but my call to node-set() fails. I've tried:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" extension-element-prefixes="msxsl" version="1.0">
Here is the XML:
<illustratedPartsCatalog>
<figure id="fig1">...</figure>
<catalogSeqNumber assyCode="00" figureNumber="01" indenture="0" item="000" itemVariant="A" subSubSystemCode="0" subSystemCode="0" systemCode="00">
<itemSeqNumber itemSeqNumberValue="000">
<quantityPerNextHigherAssy>XX</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="00000" partNumberValue="11111-111">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>VALVE ASSEMBLY</descrForPart></itemIdentData>
</partSegment><applicabilitySegment><usableOnCodeAssy>X</usableOnCodeAssy>
</applicabilitySegment></itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber>...</catalogSeqNumber>
<catalogSeqNumber>...</catalogSeqNumber>
<catalogSeqNumber>...</catalogSeqNumber>
<catalogSeqNumber>...</catalogSeqNumber>
<figure id="fig2">...</figure>
<catalogSeqNumber>...</catalogSeqNumber>
<catalogSeqNumber>...</catalogSeqNumber>
<catalogSeqNumber>...</catalogSeqNumber>
<catalogSeqNumber>...</catalogSeqNumber>
<catalogSeqNumber>...</catalogSeqNumber>
</illustratedPartsCatalog>
XSLT:
<xsl:variable name="sortedCSN">
<xsl:for-each select="illustratedPartsCatalog/catalogSeqNumber">
<xsl:sort select="concat(itemSeqNumber/partRef/#partNumberValue, #figureNumber,#item)"/>
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:variable>
<xsl:template name="SortParts2" >
<xsl:for-each select="msxsl:node-set($sortedCSN)/catalogSeqNumber">
<xsl:sort select="concat(itemSeqNumber/partRef/#partNumberValue, #figureNumber,#item)"/>
<xsl:call-template name="catalogSeqNumber-NI">
<xsl:with-param name="figNo" select="concat(#figureNumber,#figureNumberVariant)"/>
<xsl:with-param name="prfigNo" select="concat(preceding-sibling::catalogSeqNumber/#figureNumber,preceding-sibling::catalogSeqNumber/#figureNumberVariant)" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="catalogSeqNumber-NI">
<xsl:param name="figNo"/>
<xsl:param name="prfigNo" />
<fo:table-row keep-together.within-page="always" wrap-option="wrap">
<fo:table-cell xsl:use-attribute-sets="table.cell.padding" text-transform="uppercase" wrap-option="wrap">
<fo:block wrap-option="wrap">
<xsl:value-of select=" ./itemSeqNumber/partRef/#partNumberValue"/>
</fo:block>
</fo:table-cell>
<fo:table-cell xsl:use-attribute-sets="table.cell.padding" text-align="start">
<xsl:choose>
<xsl:when test="$figNo">
<fo:block>
<xsl:text> </xsl:text><xsl:value-of select="$figNo"/><xsl:text> </xsl:text> <xsl:value-of select="$prfigNo"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block />
</xsl:otherwise>
</xsl:choose>
</fo:table-cell>
<fo:table-cell xsl:use-attribute-sets="table.cell.padding" text-align="start">
<fo:block>
<xsl:if test="./itemSeqNumber/partLocationSegment/notIllustrated">
<xsl:text>-</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="#item">
<xsl:variable name="itemNo">
<xsl:call-template name="suppressZero" >
<xsl:with-param name="pText" select="#item"/>
</xsl:call-template>
</xsl:variable>
<xsl:text> </xsl:text>
<xsl:value-of select="concat($itemNo,#itemVariant)"/>
</xsl:when>
<xsl:otherwise />
</xsl:choose>
</fo:block>
</fo:table-cell>
<fo:table-cell xsl:use-attribute-sets="table.cell.padding">
<fo:block>
<xsl:value-of select="./itemSeqNumber/quantityPerNextHigherAssy"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
I think the default for Antenna House on Windows is to use MSXML so the attempt with xmlns:msxsl="urn:schemas-microsoft-com:xslt" is fine as far as using the node-set extension function.
I think you simply need to change the XSLT to
<xsl:variable name="sortedCSN">
<xsl:for-each select="illustratedPartsCatalog/catalogSeqNumber">
<xsl:sort select="concat(itemSeqNumber/partRef/#partNumberValue, #figureNumber,#item)"/>
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:variable>
<xsl:template name="SortParts2" >
<xsl:for-each select="msxsl:node-set($sortedCSN)/catalogSeqNumber">
<xsl:sort select="concat(itemSeqNumber/partRef/#partNumberValue, #figureNumber,#item)"/>
<xsl:call-template name="catalogSeqNumber-NI">
<xsl:with-param name="figNo" select="concat(#figureNumber,#figureNumberVariant)"/>
<xsl:with-param name="prfigNo" select="concat(preceding-sibling::catalogSeqNumber/#figureNumber,preceding-sibling::catalogSeqNumber/#figureNumberVariant)" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
to make sense with the input you have shown (as far as you have shown it, can't judge all those xsl:sort attempts without seeing the data to be sorted).
On the other hand, if you get errors about the stylesheet not being correct XSLT or XML, you would better show us a minimal but complete stylesheet allowing us to reproduce the problem.

Table of Contents XSL-FO XSLT 1.0

XML:
<levelledPara><title>Tools List and Tool Illustrations</title>
<levelledPara><title>General</title>
<levelledPara><para>The special tools, fixtures, and equipment needed.</para></levelledPara></levelledPara>
XSLT:
<xsl:template match="levelledPara" name="levelledPara" mode="tocdm">
<xsl:if test="*[self::title] and not(parent::*[self::levelledPara])">
<xsl:variable name="id">
<xsl:call-template name="para.id"/>
</xsl:variable>
<fo:table-row>
<fo:table-cell xsl:use-attribute-sets="table.cell.padding1" number-columns-spanned="2">
<fo:block text-transform="capitalize" text-align-last="justify" text-indent="21mm">
<xsl:number count="levelledPara" from="content" level="multiple" format="1.1.1.1.1"/>
<xsl:text>   </xsl:text>
<xsl:value-of select="title" /><fo:leader leader-pattern="dots"/><fo:basic-link internal-destination="{$id}"><fo:page-number-citation ref-id="{$id}"/></fo:basic-link>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:if>
</xsl:template>
<xsl:template match="levelledPara">
<fo:list-block
provisional-distance-between-starts="21mm"
provisional-label-separation="4pt">
<fo:list-item space-after="8pt" space-before="13pt" start-indent="0pt">
<xsl:variable name="id">
<xsl:if test="*[self::title] and not(parent::*[self::levelledPara])">
<xsl:call-template name="para.id"/>
</xsl:if>
</xsl:variable>
<fo:list-item-label
end-indent="label-end()"
text-align="start">
<fo:block font-weight="bold" id="{$id}">
<xsl:if test="not(./table)">
<xsl:number count="levelledPara" from="content" level="multiple" format="1.1.1.1.1"/>
</xsl:if>
</fo:block>
</fo:list-item-label>
<fo:list-item-body
start-indent="body-start()">
<xsl:apply-templates/>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>
<xsl:template name="para.id">
<xsl:param name="object" select="."/>
<xsl:apply-templates select="ancestor::dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/>
<xsl:choose>
<xsl:when test="$object/#id">
<xsl:value-of select="$object/#id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(count(ancestor::node()),'00000000',count(preceding::node()))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The first titled levelledPara should be included in the Table of Contents. In my sample markup none have IDs. The page number wasn't resolving because I forgot to assign an id to the fo:block for levelledPara.
You've shown the XSLT for the table of contents. The ID in the TOC should match an ID in the main text of your document.
So the template match="levelledPara" should contain a block that sets the ID:
<xsl:variable name="lpcode"><xsl:value-of select="$dmcode" /><xsl:value-of select="generate-id(.)" /></xsl:variable>
<fo:block id="{$lpcode}">

Replace element text in XSLT

I have following code:
<xsl:if test="#class = 'abc' and name(.) = 'span'">
<xsl:call-template name="multiReplace">
<xsl:with-param name="pText" select="."/>
</xsl:call-template>
</xsl:if>
The template "multiReplace" is finding old value and replacing new values.
I want to replace the following span text with NewText text :
<span class="abc">Old:</span>
to
<span class="abc">NewText:</span>
but I am getting :
<span class="abc">Old:NewText:</span>
below is the other related code:
<my:params xml:space="preserve">
<pattern>
<old>Old: </old>
<new>NewText:</new>
</pattern>
<pattern>
<old>Contact</old>
<new>Phone</new>
</pattern>
</my:params>
<xsl:variable name="vPats" select="document('')/*/my:params/*"/>
<xsl:template name="multiReplace">
<xsl:param name="pText" select="."/>
<xsl:param name="pPatterns" select="$vPats"/>
<xsl:if test="string-length($pText) > 0">
<xsl:variable name="vPat" select="$vPats[starts-with($pText, old)][1]"/>
<xsl:choose>
<xsl:when test="not($vPat)">
<xsl:copy-of select="substring($pText,1,1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$vPat/new/node()"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="multiReplace">
<xsl:with-param name="pText" select="substring($pText, 1 + not($vPat) + string-length($vPat/old/node()))"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Can you please take a look, what is the error here?

<fo:basic-link> not creating clickable link XSL-FO XSLT 1.0

Given this XML:
<figure id="fig-0011">
<title>Removal of Shipping Kit(s)</title>
<graphic id="fig-0011-gra-0001" infoEntityIdent="66503-00129-A-001-01"></graphic>
</figure>
and
<proceduralStep><para>Remove screw (see <internalRef internalRefId="fig-0011" internalRefTargetType="irtt01"></internalRef>)
<proceduralStep><para>Remove two screws (10) (see <internalRef internalRefId="fig-0011-gra-0001" internalRefTargetType="irtt09"></internalRef>),
I'm trying to create links to the figures and graphics. The link to the figure is working correctly, but the link to the graphic is not:
<fo:basic-link>
<xsl:attribute name="internal-destination"><xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/><xsl:value-of select="#internalRefId"/></xsl:attribute>
<xsl:variable name="targetElement" select="local-name(key('id',#internalRefId))"/>
<xsl:for-each select="key('id',(#internalRefId))">
<xsl:choose>
<xsl:when test="$targetElement='graphic'">
<xsl:text>Fig </xsl:text>
<xsl:number count="figure" from="content" level="any"/>
</xsl:when>
<xsl:when test="$targetElement='figure'">
<xsl:text>Fig </xsl:text>
<xsl:number count="figure" from="content" level="any"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
Key:
<xsl:key name="id" match="*" use="#id"/>
Figure:
<xsl:template match="figure">
<xsl:apply-templates select="graphic"/>
</xsl:template>
<xsl:template match="figure/graphic" priority="10">
<fo:block text-align="center" start-indent="0pt" color="black" keep-with-next="always">
<xsl:call-template name="do-graphic">
<xsl:with-param name="include-graphic" select="true()"/>
</xsl:call-template>
</fo:block>
<xsl:if test="position()=last()">
<xsl:apply-templates select="../legend"/>
</xsl:if>
<xsl:if test="#infoEntityIdent">
<fo:block text-align="right" keep-with-previous="always">
<xsl:value-of select="#infoEntityIdent"/>
</fo:block>
</xsl:if>
<fo:block font-weight="normal" font-style="italic" text-align="center" space-before="12pt" space-after="8pt" start-indent="0pt" keep-with-previous="always">
<xsl:if test="../#id">
<xsl:attribute name="id"><xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/><xsl:value-of select="../#id"/></xsl:attribute>
</xsl:if>
<xsl:text>Fig </xsl:text>
<xsl:number count="figure" level="any" format="1" from="content"/>
<xsl:apply-templates select="../title"/>
<xsl:variable name="numSheets" select="count(../graphic)"/>
<xsl:choose>
<xsl:when test="$numSheets>1">
<xsl:text> (Sheet </xsl:text>
<xsl:number count="graphic" level="any" format="1" from="figure"/>
<xsl:text> of </xsl:text>
<xsl:value-of select="$numSheets"/>
<xsl:text>)</xsl:text>
</xsl:when>
</xsl:choose>
</fo:block>
Graphic:
<xsl:template match="graphic">
<fo:inline-container>
<fo:block space-before="12pt" space-before.conditionality="retain">
<xsl:call-template name="do-graphic"/>
</fo:block>
</fo:inline-container>
</xsl:template>
<xsl:template name="do-graphic">
<xsl:param name="include-graphic" select="true()"/>
<xsl:variable name="content-width">
<xsl:choose>
<xsl:when test="#reproductionWidth != ''">
<xsl:value-of select="#reproductionWidth"/>
</xsl:when>
<!-- coding for reproduction scale based on clarifications in Issue 4.1 -->
<xsl:when test="#reproductionScale != ''">
<xsl:value-of select="#reproductionScale"/>
<xsl:text>%</xsl:text>
</xsl:when>
<xsl:otherwise>95%</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="content-height">
<xsl:choose>
<xsl:when test="#reproductionHeight != ''">
<xsl:value-of select="#reproductionHeight"/>
</xsl:when>
<xsl:when test="#reproductionScale != ''">
<xsl:value-of select="#reproductionScale"/>
<xsl:text>%</xsl:text>
</xsl:when>
<xsl:otherwise>95%</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$include-graphic">
<fo:external-graphic src="{unparsed-entity-uri(#infoEntityIdent)}" scaling="uniform" content-height="{$content-height}" content-width="{$content-width}"/>
</xsl:when>
<xsl:otherwise>
<fo:inline-container display-align="center" text-align="center" block-progression-dimension="{$content-height}" inline-progression-dimension="{$content-width}" background-color="silver" color="red">
<fo:block>Graphic Not Included</fo:block>
</fo:inline-container>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
This returns:
Remove two screws (10) (see Fig 2)
which is the correct figure number, but the 2 is not a clickable link to the graphic.
The dmcode template builds a string. If I remove that from the XSLT then the figure number no longer links to the figure.
I am using XSLT 1.0. I appreciate any help, thank you.
The second internalRef refers to a graphic. It appears that your XSLT is not copying the graphic/#id into the FO in the result tree. With AH Formatter and a stylesheet that doesn't copy graphic/#id, I get no link and the error message:
Unresolved internal-destination: "fig-0011-gra-0001".
It appears that your FO formatter also isn't making the link when there's no matching target ID.
I can't help you much more without seeing your xsl:key declaration(s), the templates for figure and graphic, and knowing whether graphic can appear outside of figure.
Reedited to use figure/#id and graphic/#id:
<xsl:key name="id" match="*" use="#id" />
<xsl:variable name="prefix">
<xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode" />
</xsl:variable>
<xsl:template match="internalRef">
<xsl:for-each select="key('id', #internalRefId)">
<fo:basic-link internal-destination="{$prefix}{#id}">
<xsl:text>Fig </xsl:text>
<xsl:number count="figure" from="content" level="any" />
</fo:basic-link>
</xsl:for-each>
</xsl:template>
<xsl:template match="figure">
<fo:wrapper id="{#id}">
<xsl:apply-templates select="graphic" />
</fo:wrapper>
</xsl:template>
<xsl:template match="figure/graphic" priority="10">
<fo:block text-align="center" start-indent="0pt" color="black" keep-with-next="always">
<xsl:if test="#id">
<xsl:attribute name="id">
<xsl:value-of select="$prefix" />
<xsl:value-of select="#id" />
</xsl:attribute>
</xsl:if>
<xsl:call-template name="do-graphic">
<xsl:with-param name="include-graphic" select="true()" />
</xsl:call-template>
</fo:block>
<xsl:if test="position() = last()">
<xsl:apply-templates select="../legend" />
</xsl:if>
<xsl:if test="#infoEntityIdent">
<fo:block text-align="right" keep-with-previous="always">
<xsl:value-of select="#infoEntityIdent" />
</fo:block>
</xsl:if>
<fo:block font-weight="normal" font-style="italic" text-align="center" space-before="12pt" space-after="8pt" start-indent="0pt" keep-with-previous="always">
<xsl:text>Fig </xsl:text>
<xsl:number count="figure" level="any" format="1" from="content" />
<xsl:apply-templates select="../title" />
<xsl:variable name="numSheets" select="count(../graphic)" />
<xsl:choose>
<xsl:when test="$numSheets > 1">
<xsl:text> (Sheet </xsl:text>
<xsl:number count="graphic" level="any" format="1" from="figure" />
<xsl:text> of </xsl:text>
<xsl:value-of select="$numSheets" />
<xsl:text>)</xsl:text>
</xsl:when>
</xsl:choose>
</fo:block>
</xsl:template>
I also moved the graphic's ID to the first fo:block in the figure/graphic template. Having it on the last fo:block would have meant scrolling up to see the graphic every time that you followed a link to a graphic.
It was suggested to add <xsl:attribute name="id"> to the <fo:external-graphic> in the do-graphic template and that seems to solve the problem:
<xsl:template name="do-graphic">
<xsl:param name="include-graphic" select="true()"/>
<xsl:variable name="content-width">
<xsl:choose>
<xsl:when test="#reproductionWidth != ''">
<xsl:value-of select="#reproductionWidth"/>
<xsl:call-template name="checkForUom">
<xsl:with-param name="measure" select="#reproductionWidth"/>
</xsl:call-template>
</xsl:when>
<!-- coding for reproduction scale based on clarifications in Issue 4.1 -->
<xsl:when test="#reproductionScale != ''">
<xsl:value-of select="#reproductionScale"/>
<xsl:text>%</xsl:text>
</xsl:when>
<xsl:otherwise>95%</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="content-height">
<xsl:choose>
<xsl:when test="#reproductionHeight != ''">
<xsl:value-of select="#reproductionHeight"/>
<xsl:call-template name="checkForUom">
<xsl:with-param name="measure" select="#reproductionWidth"/>
</xsl:call-template>
</xsl:when>
<!-- coding for reproduction scale based on clarifications in Issue 4.1 -->
<xsl:when test="#reproductionScale != ''">
<xsl:value-of select="#reproductionScale"/>
<xsl:text>%</xsl:text>
</xsl:when>
<xsl:otherwise>95%</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$include-graphic">
<fo:external-graphic src="{unparsed-entity-uri(#infoEntityIdent)}" scaling="uniform" content-height="{$content-height}" content-width="{$content-width}">
<xsl:attribute name="id"><xsl:apply-templates select="//dmodule/identAndStatusSection/dmAddress/dmIdent/dmCode"/><xsl:value-of select="#id"/></xsl:attribute>
</fo:external-graphic>
</xsl:when>
<xsl:otherwise>
<fo:inline-container display-align="center" text-align="center" block-progression-dimension="{$content-height}" inline-progression-dimension="{$content-width}" background-color="silver" color="red">
<fo:block>Graphic Not Included</fo:block>
</fo:inline-container>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

XSLT split string on every character

I have a string like : "ABCDEFGHI"
I want the output as A,B,C,D,E,F,G,H,I in xslt-
I have been using -
<xsl:variable name="string_Comma_Delimited">a,b,c,d,e,f,g,h,i</xsl:variable>
<xsl:call-template name="parseString">
<xsl:with-param name="list" select="$string_Comma_Delimited"/>
</xsl:call-template>
<xsl:template name="parseString">
<xsl:param name="list"/>
<xsl:if test="contains($list, ',')">
<fo:table-cell border-width="0.000pt " border-style="solid" border-color="rgb(0,0,0)" padding-top="4.000pt">
<fo:block-container height="6mm" border-width="0.200pt" border-style="solid" border-color="rgb(0,0,0)" text-align="center">
<fo:block text-align="center">
<xsl:value-of select="substring-before($list, ',')"/>
</fo:block>
</fo:block-container>
</fo:table-cell>
<xsl:call-template name="parseString">
<xsl:with-param name="list" select="substring-after($list, ',')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Your current template splits the string by commas. To simply split it on every single character you can still use a recursive template. All the template would do is output the first character using substring, and then, if the length of the string was 2 or more characters, recursively call the template with the remaining portion of the string.
Try this
<xsl:template name="parseString">
<xsl:param name="text"/>
<letter>
<xsl:value-of select="substring($text, 1, 1)"/>
</letter>
<xsl:if test="string-length($text) > 1">
<xsl:call-template name="parseString">
<xsl:with-param name="text" select="substring($text, 2, string-length($text) - 1)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Given INDIA as input, the following is output:
<letter>I</letter>
<letter>N</letter>
<letter>D</letter>
<letter>I</letter>
<letter>A</letter>
Now, if you were using XSLT 2.0, you could use the xsl:analyze-string function to achieve the same
<xsl:template name="parseString">
<xsl:param name="text"/>
<xsl:analyze-string select="$text" regex=".">
<xsl:matching-substring>
<letter>
<xsl:value-of select="." />
</letter>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
(Of course, if you were using XSLT 2.0, you could have used tokenize in the first case to split the comma-delimited string)