Page 1 of 1

How create markup?

Posted: Sun Apr 04, 2021 3:25 pm
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!

Re: How create markup?

Posted: Mon Apr 05, 2021 9:28 am
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

Re: How create markup?

Posted: Mon Apr 05, 2021 9:24 pm
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