How create markup?

Questions about XML that are not covered by the other forums should go here.
levvusss
Posts: 2
Joined: Sun Apr 04, 2021 3:22 pm

How create markup?

Post by levvusss »

Hello. I have "price" field, like:

Code: Select all

<price>2411</price>
how tranform it, add markup for example +10%?

Code: Select all

<price>2652</price>
Thank you!
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: How create markup?

Post by Radu »

Hi,

If you have an XML document like this:

Code: Select all

<root>
    <price>2411</price>
</root>
you can create an XSLT stylesheet which adds 10% to all price elements, it would look something like this:

Code: Select all

<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="price">
        <xsl:variable name="priceNumber" select="xs:integer(text())"/>
        <xsl:value-of select="$priceNumber + ($priceNumber * 10) div 100"/>
    </xsl:template>
</xsl:stylesheet>
More about processing XML with XSLT:
https://www.oxygenxml.com/doc/versions/ ... -xslt.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
levvusss
Posts: 2
Joined: Sun Apr 04, 2021 3:22 pm

Re: How create markup?

Post by levvusss »

Radu wrote: Mon Apr 05, 2021 9:28 am Hi,

If you have an XML document like this:

Code: Select all

<root>
    <price>2411</price>
</root>
you can create an XSLT stylesheet which adds 10% to all price elements, it would look something like this:

Code: Select all

<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="price">
        <xsl:variable name="priceNumber" select="xs:integer(text())"/>
        <xsl:value-of select="$priceNumber + ($priceNumber * 10) div 100"/>
    </xsl:template>
</xsl:stylesheet>
More about processing XML with XSLT:
https://www.oxygenxml.com/doc/versions/ ... -xslt.html

Regards,
Radu
Thank you
I will try
Post Reply