0

`

<Telephone>1234 64 79 31 6,345664 01 04 23, 55551 04 24</Telephone>

` There is a tridion component, which has telephone number as a simple text field.multiple numbers are given in that field separated by a comma.But on application i want them to come in a new line.

1 Answer 1

5

based on: https://stackoverflow.com/questions/4845660/xsl-how-to-split-strings

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tridion="http://www.xyz.com/tridion/schemas">

<xsl:output method="xml" encoding="utf-8" indent="no"/>

<xsl:template match="tridion:Office/tridion:Telephone/text()" name="split">
    <xsl:param name="pText" select="."/>
    <xsl:if test="string-length($pText)">
        <xsl:if test="not($pText=.)">
            <br />
        </xsl:if>
        <xsl:value-of select="substring-before(concat($pText,','),',')"/>
        <xsl:call-template name="split">
            <xsl:with-param name="pText" select="substring-after($pText, ',')"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>         

<xsl:template match="office" >
    <h5 id="{@id}">
        <a href="#" property="v:name">
            <xsl:value-of select="name/text()"/>
        </a>
    </h5>
    <div xmlns:v="http://rdf.data-vocabulary.org/#" typeof="v:Organization">
        <div>
            <p>
                <div class="addressDetails">

                    <xsl:if test="telephone/text()">
                        <div class="moreDetails">
                            <p>
                                <span>
                                    <xsl:value-of select="utils:Text('Telephone')"/>
                                </span>
                            </p>
                            <p>

                                <span class="normalfont" property="v:tel">
                                    <xsl:value-of select="telephone/text()"/> 

                                </span>
                            </p>
                            <div class="clearfix">
                                <xsl:comment></xsl:comment>
                            </div>

                        </div>
                    </xsl:if>
                </div>
            </p>
        </div>

    </div>
</xsl:template>

7
  • Stanislav, Thanks for your time, but what should be placed in "text()" and "pText" Feb 25, 2016 at 8:28
  • text() should be replaced with path to your node in your xml file, like "/Office/Telephone/text()" - that means that all text inside all <telephone> nodes inside all <Office> will be replaced, pText is just a name of parameter in xslt - you can left it as is. Feb 25, 2016 at 9:59
  • I have updated the xslt. The problem was in namespaces. Feb 25, 2016 at 13:48
  • I used following website to check: xslt.online-toolz.com/tools/xslt-transformation.php . And I do not see any problems with your xml and mine xslt. Is there anything else in your xml or in your resulted xslt? Feb 29, 2016 at 8:29
  • Thanks for your valuable time. I updated my xslt with some more details.and the place where i am inserting the given xslt. Feb 29, 2016 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.