How to add attribute with value

Questions about XML that are not covered by the other forums should go here.
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to add attribute with value

Post by Radu »

Hi,

Maybe you can do that with an XSLT stylesheet like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="*:text[not(@end)]">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:if test="preceding-sibling::*:text[@start]">
                <xsl:attribute name="end">
                    <xsl:value-of select="xs:integer((preceding-sibling::*:text[@start])[last()]/@start) + 1"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com