Answer the question
In order to leave comments, you need to log in
How to dynamically add blocks or change field values when using xslt?
On hand are examples of xml and it is not known where xslt came from.
I need to have a little more freedom in my actions and would like:
<?xml version="1.0" encoding="UTF-8"?>
<Statement xmlns="http://ююю"
xmlns:a="urn:iso:std:iso:20022:tech:xsd:camt.053.001.04">
<acceptDate>2018-11-28T13:23:43</acceptDate>
<account>88888888888888888888</account>
<bankBIC>5555555555</bankBIC>
<creditReturn>1600000.00</creditReturn>
<creditReturnNat>1600000.00</creditReturnNat>
<currCode>RUB</currCode>
<debetReturn>0.00</debetReturn>
<debetReturnNat>0.00</debetReturnNat>
<externalId>ABC59913</externalId>
<docDate>2018-11-28T13:23:43</docDate>
<fromDate>2018-11-28T00:00:00</fromDate>
<isFinal>1</isFinal>
<toDate>2018-11-28T00:00:00</toDate>
<inboundBalance>2296351.83</inboundBalance>
<inboundBalanceNat/>
<outboundBalance>3896351.83</outboundBalance>
<outboundBalanceNat/>
<operations>
<Operation>
....
</Operation>
</operations>
</Statement>
Answer the question
In order to leave comments, you need to log in
Once for the test, you can write the same type of data
data.xml
<?xml version="1.0"?>
<root>
<foo/>
</root>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<operations>
<xsl:call-template name="operation">
<xsl:with-param name="counter" select="5"/>
</xsl:call-template>
</operations>
</xsl:template>
<xsl:template name="operation">
<xsl:param name="counter" select="1"/>
<operation>
<name>
<xsl:text>Ivan</xsl:text>
<xsl:value-of select="$counter"/>
</name>
<price>
<xsl:value-of select="100 * $counter"/>
</price>
</operation>
<xsl:if test="$counter > 0">
<xsl:call-template name="operation">
<xsl:with-param name="counter" select="$counter - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
xsltproc proc.xsl data.xml > result.xml
cat result.xml
<?xml version="1.0"?>
<operations>
<operation>
<name>Ivan5</name>
<price>500</price>
</operation>
<operation>
<name>Ivan4</name>
<price>400</price>
</operation>
<operation>
<name>Ivan3</name>
<price>300</price>
</operation>
<operation>
<name>Ivan2</name>
<price>200</price>
</operation>
<operation>
<name>Ivan1</name>
<price>100</price>
</operation>
<operation>
<name>Ivan0</name>
<price>0</price>
</operation>
</operations>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<operations>
<xsl:for-each select="1 to 10">
<operation>
<name>
<xsl:text>Ivan</xsl:text>
<xsl:value-of select="position()"/>
</name>
<price>
<xsl:value-of select="100 * position()"/>
</price>
</operation>
</xsl:for-each>
</operations>
</xsl:template>
</xsl:stylesheet>
saxonb-xslt -s:data.xml -xsl:proc.xsl -o:result.xml
cat result.xml
<?xml version="1.0" encoding="UTF-8"?>
<operations>
<operation>
<name>Ivan1</name>
<price>100</price>
</operation>
<operation>
<name>Ivan2</name>
<price>200</price>
</operation>
<operation>
<name>Ivan3</name>
<price>300</price>
</operation>
<operation>
<name>Ivan4</name>
<price>400</price>
</operation>
<operation>
<name>Ivan5</name>
<price>500</price>
</operation>
<operation>
<name>Ivan6</name>
<price>600</price>
</operation>
<operation>
<name>Ivan7</name>
<price>700</price>
</operation>
<operation>
<name>Ivan8</name>
<price>800</price>
</operation>
<operation>
<name>Ivan9</name>
<price>900</price>
</operation>
<operation>
<name>Ivan10</name>
<price>1000</price>
</operation>
</operations
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question