Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 31st, 2013, 10:37 AM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:12 PM.


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