Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2013, 10:37 AM
Authorized User
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default String concatenation with linking

I've the below 4 cases in XML. I need a template match with regex tht can solve my below problem.

HTML Code:
<toc>
<secondaryie>Practice Direction, PD1.1/1—PD1.1/9</secondaryie>
<secondaryie>preliminary act</secondaryie>
<secondaryie>collision actions, 75/20</secondaryie>
<secondaryie>failure to lodge, E75/19/32</secondaryie>
</toc>
And the output i'm expecting is as below.

HTML Code:
<div class="secondaryie">Practice Direction,<a href="sec_1_PD1-1/1">PD1.1/1</a>—<a href="sec_1_PD1-1/9">PD1.1/9</a><div>
<div class="secondaryie">preliminary act<div>
<div class="secondaryie">collision actions,<a href="sec_1_P75/20">75/20</a><div>
<div class="secondaryie">failure to lodge,<span class="invalid">E75/19/32</span><div>
here for the last case the hint is, if the number is preceded any character apart from PD, it should create an invalid tag. Please let me know how i can do this.

Tried XSLT is as below

HTML Code:
 <xsl:template match="secondaryie">
        <div class="secondaryie">
            <xsl:apply-templates/>
        </div>
    </xsl:template>



<xsl:template match="text()">

        <xsl:analyze-string select="." regex="[\d/]+">

            <xsl:matching-substring>
                <xsl:variable name="range" select="tokenize(.,'—')"/>
                <xsl:variable name="pg" select="tokenize(.,'/')"/>
<xsl:choose>
    <xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ',substring(.,1,1)))">

        <xsl:choose>
                    <xsl:when test="contains($pg[3],'—')">
                        <xsl:variable name="range-pg" as="item()*">
                            <xsl:for-each select="$range">
                                <xsl:sequence select="tokenize(.,'/')"/>
                            </xsl:for-each>
                        </xsl:variable>
                        <xsl:for-each select="xs:integer($range-pg[3]) to xs:integer($range-pg[6])">
                            <a href="er:#HKWBV1_ORD_{
                                if (string(number($range-pg[1]))!='NaN') then 
                                format-number(number($range-pg[1]),'00') 
                                else 
                                $range-pg[1]}/P{string-join($range-pg[position()=(1,2)],'/')}/{.}">
                                <xsl:value-of select="concat(string-join($range-pg[position()=(1,2)],'/'),'/',.)"/>
                            </a>
                            <xsl:text>, </xsl:text>
                        </xsl:for-each>
                    </xsl:when>
                    <xsl:otherwise>
                        <a href="er:#HKWBV1_ORD_{
                            if (string(number($pg[1]))!='NaN') then 
                            format-number(number($pg[1]),'00') 
                            else 
                            $pg[1]}/P{$pg[1]
                            }/{string-join($pg[position()>1],'/')}">
                            <xsl:value-of select="."/>
                        </a>                            
                    </xsl:otherwise>
                </xsl:choose>

    </xsl:when>


    <xsl:otherwise>
<xsl:choose>
    <xsl:when test="contains('PD',substring(.,1,2))">

<a href="{concat('HKWBV1_SEC_',substring-after(substring-before(.,'/'),'PD'),'/PPD',translate(substring-after(.,'PD'),'.','-'))}">
<xsl:value-of select="."/>
</a>




</xsl:when>
<xsl:otherwise>
    <span class="invalid">
<xsl:value-of select="."/>  
    </span>
    </xsl:otherwise>
</xsl:choose>
   </xsl:otherwise>
</xsl:choose>
     </xsl:matching-substring>
            <xsl:non-matching-substring>
                <xsl:value-of select="."/>
            </xsl:non-matching-substring>
        </xsl:analyze-string>           
</xsl:template>
Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance in String concatenation rushman XSLT 4 September 27th, 2007 11:02 AM
String concatenation query. AjayLuthria XSLT 2 March 14th, 2007 11:55 AM
string concatenation nulogix PHP How-To 1 June 24th, 2004 06:17 AM
string concatenation matt_99 Access VBA 2 January 17th, 2004 09:55 AM
T-SQL String Concatenation jaucourt SQL Language 2 January 13th, 2004 10:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.