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 March 6th, 2009, 01:55 AM
Authorized User
 
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Question regex-group problem in XSLT

dear sir


input:==>

<link linkend="b10" type="bib"><emph type="italic">The handbook of English linguistics</emph> Sless Tarjat Penman 2001</link>

output:==>

The handbook of English linguistics Sless Tarjat Penman <xref ref-type="bibr" xlink:href="ref010">2001</xref>


expected output:==>

<emphasis type="italic">The handbook of English linguistics</emphasis> Sless Tarjat Penman <xref ref-type="bibr" xlink:href="ref010">2001</xref>







and i have written XSLT as follows:


<xsl:template match="link[@type='bib']">
<xsl:variable name="year" select="."/>
<xsl:analyze-string select="$year" regex="\s*(.*?\s*\w*)\s*(\d{{4}})\s*(\w*\s*.*?)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
<xsl:element name="xref">
<xsl:attribute name="ref-type">bibr</xsl:attribute>
<xsl:choose>
<xsl:when test="string-length($bslt)=1">
<xsl:attribute name="xlink:href" namespace="href">ref00<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:when>
<xsl:when test="string-length($bslt)=2">
<xsl:attribute name="xlink:href" namespace="href">ref0<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="xlink:href" namespace="href">ref<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="regex-group(2)"/>
<xsl:value-of select="regex-group(3)"/>
</xsl:element>&rpar;
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>

<xsl:template match="emph[@type='italic']">
<xsl:element name="emphasis">
<xsl:attribute name="type">italic</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>


and i am not getting the required output what will be the problem?
please help me

thanks & regards
Rajashekhara
 
Old March 6th, 2009, 02:45 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try this:

Code:
 
<xsl:template match="link[@type='bib']">
<xsl:variable name="year" select="text()"/>
<xsl:variable name="bslt" select=" substring-after(@linkend, 'b')"/>
<xsl:variable name="name" select="$bslt"></xsl:variable>
<xsl:apply-templates select="emph"></xsl:apply-templates>
<xsl:analyze-string select="text()[2]" regex="(\s)(.*)(\d{{4}})\s*(\w*\s*.*?)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
<xsl:value-of select="regex-group(2)"/>
<xsl:element name="xref">
<xsl:attribute name="ref-type">bibr</xsl:attribute>
<xsl:choose>
<xsl:when test="string-length($name)=1">
<xsl:attribute name="xlink:href" namespace="href">ref00<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:when>
<xsl:when test="string-length($name)=2">
<xsl:attribute name="xlink:href" namespace="href">ref0<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="xlink:href" namespace="href">ref<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="regex-group(3)"/>
<xsl:value-of select="regex-group(4)"/> 
</xsl:element>
</xsl:matching-substring>
</xsl:analyze-string>

</xsl:template>

<xsl:template match="emph[@type='italic']">
<emphasis type="italic">
<xsl:value-of select="."></xsl:value-of>
</emphasis>
</xsl:template>


__________________
Rummy
The Following User Says Thank You to mrame For This Useful Post:
rajashekhara (March 6th, 2009)
 
Old March 6th, 2009, 03:01 AM
Authorized User
 
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

no its not working,

i think, actual problem with
<xsl:value-of select="regex-group(1)"/>

for that its not converting any tags which are inside the <link> tag


thanks & regards
Rajashekhara
 
Old March 6th, 2009, 03:06 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Did you try with the code I posted? I have changed your code. Copy and past my code and then check again. The regex-group(1) in my code just selects the space.
__________________
Rummy
The Following User Says Thank You to mrame For This Useful Post:
rajashekhara (March 6th, 2009)
 
Old March 6th, 2009, 03:13 AM
Authorized User
 
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

ok that is not my question.


<xsl:analyze-string select="$year" regex="(\s)(.*)(\d{{4}})\s*(\w*\s*.*?">
in this
"
<xsl:value-of select="regex-group(2)"/> " is selecting only text not any tags


thanks & regards
Rajashekhara
 
Old March 6th, 2009, 03:20 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Yes it wont select any tags as I have selected the text (" Sless Tarjat Penman 2001") part thro' analyze-string. I have referenced the <emph> tag using apply-templates. So the regex-group(1) will select the space, second group will select the text and third will select the year. Is it clear?
__________________
Rummy
 
Old March 6th, 2009, 03:22 AM
Authorized User
 
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

i want to select text as well as tags, what to do for that
 
Old March 6th, 2009, 04:10 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

In your code the variable $year will give the ouput "
The handbook of English linguistics Sless Tarjat Penman 2001". So this text is only processed.
__________________
Rummy
 
Old March 6th, 2009, 04:14 AM
Authorized User
 
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

no, my input is

<link linkend="b10" type="bib"><emph type="italic">The handbook of English linguistics</emph> Sless Tarjat Penman 2001</link>


and i want output like this

<emphasis type="italic">The handbook of English linguistics</emphasis> Sless Tarjat Penman <xref ref-type="bibr" xlink:href="ref010">2001</xref>


thanks & regards
Rajashekhara
 
Old March 6th, 2009, 04:28 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try this:

Code:
 
<xsl:template match="link[@type='bib']">
<xsl:variable name="year" select="text()"/>
<xsl:variable name="bslt" select=" substring-after(@linkend, 'b')"/>
<xsl:variable name="name" select="$bslt"></xsl:variable>
<xsl:apply-templates select="emph"></xsl:apply-templates>
<xsl:analyze-string select="text()" regex="(\s)(.*)(\d{{4}})\s*(\w*\s*.*?)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
<xsl:value-of select="regex-group(2)"/>
<xsl:element name="xref">
<xsl:attribute name="ref-type">bibr</xsl:attribute>
<xsl:choose>
<xsl:when test="string-length($name)=1">
<xsl:attribute name="xlink:href" namespace="href">ref00<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:when>
<xsl:when test="string-length($name)=2">
<xsl:attribute name="xlink:href" namespace="href">ref0<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="xlink:href" namespace="href">ref<xsl:value-of select="$bslt"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="regex-group(3)"/>
<xsl:value-of select="regex-group(4)"/> 
</xsl:element>
</xsl:matching-substring>
</xsl:analyze-string>

</xsl:template>

<xsl:template match="emph[@type='italic']">
<emphasis type="italic">
<xsl:value-of select="."></xsl:value-of>
</emphasis>
</xsl:template>

__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using for-each-group in an XSLT statement Kayan XSLT 2 January 16th, 2009 12:52 PM
regex in xslt rajesh_css XSLT 4 September 29th, 2008 11:35 PM
XSLT simulation of two column Group By wholden XSLT 2 March 31st, 2008 08:57 AM
How to group xsl elements in xslt.10 suji XSLT 1 February 29th, 2008 03:44 AM
Regex Problem claudew BOOK: ASP.NET Website Programming Problem-Design-Solution 2 June 5th, 2004 07:55 PM





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