Add and Subtract to numerical suffix
Here should go questions about transforming XML with XSLT and FOP.
			- 
				JackFrost
 - Posts: 1
 - Joined: Thu Jun 02, 2016 12:03 pm
 
Add and Subtract to numerical suffix
Any suggestion for an XSLT script where I can transfor this:
<a href="chapter-15.xhtml#b838"><span id="b235"/>
to this:
<a href="chapter-15.xhtml#b840"><span id="b232"/>
I just added 2 to the a href tag and subtracted 2 from the span id tag
Thanks in advance
			
			
									
									
						<a href="chapter-15.xhtml#b838"><span id="b235"/>
to this:
<a href="chapter-15.xhtml#b840"><span id="b232"/>
I just added 2 to the a href tag and subtracted 2 from the span id tag
Thanks in advance
- 
				Radu
 - Posts: 9547
 - Joined: Fri Jul 09, 2004 5:18 pm
 
Re: Add and Subtract to numerical suffix
Hi,
The XSLT stylesheet would need to look something like this:
Ideally you should pose XSLT-related issues on the XSLT mailing list:
http://www.mulberrytech.com/xsl/xsl-list/
Regards,
Radu
			
			
									
									The XSLT stylesheet would need to look something like this:
Code: Select all
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:output method="xml" indent="no"/>
    <!-- Match document -->
    
    <xsl:template match="a[contains(@href, '#b')][span]" mode="copy">
        <a>
            <xsl:variable name="base" select="substring-before(@href, '#b')"/>
            <xsl:variable name="numericAnchor" select="xs:integer(substring-after(@href, '#b')) + 2"/>
            <xsl:attribute name="href">
                <xsl:value-of select="concat($base, '#b', $numericAnchor)"/>
            </xsl:attribute>
            <xsl:apply-templates mode="copy"/>
        </a>
    </xsl:template>
    <xsl:template match="span[starts-with(@id, 'b')][parent::a[contains(@href, '#b')]]" mode="copy">
        <a>
            <xsl:variable name="numericAnchor" select="xs:integer(substring-after(@id, 'b')) - 2"/>
            <xsl:attribute name="href">
                <xsl:value-of select="concat('b', $numericAnchor)"/>
            </xsl:attribute>
            <xsl:apply-templates mode="copy"/>
        </a>
    </xsl:template>
    
    <xsl:template match="/">
        <xsl:apply-templates mode="copy" select="."/>
    </xsl:template>
    <!-- Deep copy template -->
    <xsl:template match="*|text()|@*" mode="copy">
        <xsl:copy>
            <xsl:apply-templates mode="copy" select="@*"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
    </xsl:template>
    <!-- Handle default matching -->
    <xsl:template match="*"/>
</xsl:stylesheet>http://www.mulberrytech.com/xsl/xsl-list/
Regards,
Radu
Radu Coravu 
<oXygen/> XML Editor
http://www.oxygenxml.com
						<oXygen/> XML Editor
http://www.oxygenxml.com
			
				Jump to
				
			
		
			
			
	
	- Oxygen XML Editor/Author/Developer
 - ↳ Feature Request
 - ↳ Common Problems
 - ↳ DITA (Editing and Publishing DITA Content)
 - ↳ Artificial Intelligence (AI Positron Assistant add-on)
 - ↳ SDK-API, Frameworks - Document Types
 - ↳ DocBook
 - ↳ TEI
 - ↳ XHTML
 - ↳ Other Issues
 - Oxygen XML Web Author
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen Content Fusion
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen JSON Editor
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen PDF Chemistry
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen Feedback
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen XML WebHelp
 - ↳ Feature Request
 - ↳ Common Problems
 - XML
 - ↳ General XML Questions
 - ↳ XSLT and FOP
 - ↳ XML Schemas
 - ↳ XQuery
 - NVDL
 - ↳ General NVDL Issues
 - ↳ oNVDL Related Issues
 - XML Services Market
 - ↳ Offer a Service