 |
| 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
|
|
|
|

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

March 6th, 2009, 02:45 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
|
|
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:
|
|
|

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

March 6th, 2009, 03:06 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
|
|
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:
|
|
|

March 6th, 2009, 03:13 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 6th, 2009, 03:20 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
|
|
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
|
|

March 6th, 2009, 03:22 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
i want to select text as well as tags, what to do for that
|
|

March 6th, 2009, 04:10 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
|
|
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
|
|

March 6th, 2009, 04:14 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 6th, 2009, 04:28 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
|
|
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
|
|
 |