I have the following input XML and want to copy the "Delivery" Stop elements:
<?xml version="1.0" encoding="UTF-8" ?>
<LeanXML>
<ShipperLoadPlan>
<LoadNumber>129516728</LoadNumber>
<Stops>
<Stop>
<StopNumber>1</StopNumber>
<StopType>Pickup</StopType>
<Distance UOM="mi">0</Distance>
<CalcDueDate TimeZone="EDT" TimeZoneDesc="America/New_York">09/27/2021
00:00</CalcDueDate>
<ReferenceNums/>
<OrderNums>
<OrderNum ShipperRef="6000002014_30SAP" ShipmentLegID="291"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
<OrderNum ShipperRef="6000002014_10SAP" ShipmentLegID="2916"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
</OrderNums>
</Stop>
<Stop>
<StopNumber>2</StopNumber>
<StopType>Delivery</StopType>
<Distance UOM="mi">0</Distance>
<CalcDueDate TimeZone="CDT" TimeZoneDesc="America/Chicago">10/01/2021
00:00</CalcDueDate>
<ReferenceNums/>
<OrderNums>
<OrderNum ShipperRef="R6000002014_10SAP" ShipmentLegID="291608671"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
</OrderNums>
</Stop>
<Stop>
<StopNumber>3</StopNumber>
<StopType>Delivery</StopType>
<Distance UOM="mi">473</Distance>
<CalcDueDate TimeZone="CDT" TimeZoneDesc="America/Chicago">10/03/2021
00:00</CalcDueDate>
<ReferenceNums/>
<OrderNums>
<OrderNum ShipperRef="R6000002014_30SAP" ShipmentLegID="291634632"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
</OrderNums>
</Stop>
</Stops>
<DivertedOrders/>
<CompanyDefined/>
</ShipperLoadPlan>
</LeanXML>
I came up with this XSLT using a Key I put on the StopType = Pickup:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="1.0">
<xsl:key name="keyOrderLineNum" match="Stop[StopType='Pickup']/OrderNums"
use="concat(OrderNum/#ShipperRef,'|',../../CalcDueDate,'|',../../StopNumber)"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Stop[StopType='Pickup']">
<xsl:copy>
<xsl:copy-of select="."/>
<CopiedStop>
<xsl:copy>
<xsl:value-of select="parent::Stops/Stop[StopType='Delivery']"/>
</xsl:copy>
</CopiedStop>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But I am expecting this target XML, my bit question mark is how do I properly use my key to copy the Delivery Stop elements?
Expected Target:
<?xml version="1.0" encoding="UTF-8" ?>
<LeanXML>
<ShipperLoadPlan>
<LoadNumber>129516728</LoadNumber>
<Stops>
<Stop>
<StopNumber>1</StopNumber>
<StopType>Pickup</StopType>
<Distance UOM="mi">0</Distance>
<CalcDueDate TimeZone="EDT" TimeZoneDesc="America/New_York">09/27/2021
00:00</CalcDueDate>
<ReferenceNums/>
<OrderNums>
<OrderNum ShipperRef="6000002014_30SAP" ShipmentLegID="291"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
<OrderNum ShipperRef="6000002014_10SAP" ShipmentLegID="2916"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
</OrderNums>
<CopiedStop>
<Stop>
<StopNumber>2</StopNumber>
<StopType>Delivery</StopType>
<Distance UOM="mi">0</Distance>
<CalcDueDate TimeZone="CDT" TimeZoneDesc="America/Chicago">10/01/2021
00:00</CalcDueDate>
<ReferenceNums/>
<OrderNums>
<OrderNum ShipperRef="R6000002014_10SAP" ShipmentLegID="291608671"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
</OrderNums>
</Stop>
<Stop>
<StopNumber>3</StopNumber>
<StopType>Delivery</StopType>
<Distance UOM="mi">473</Distance>
<CalcDueDate TimeZone="CDT" TimeZoneDesc="America/Chicago">10/03/2021
00:00</CalcDueDate>
<ReferenceNums/>
<OrderNums>
<OrderNum ShipperRef="R6000002014_30SAP" ShipmentLegID="291634632"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
</OrderNums>
</Stop>
</CopiedStop>
</Stop>
<Stop>
<StopNumber>2</StopNumber>
<StopType>Delivery</StopType>
<Distance UOM="mi">0</Distance>
<CalcDueDate TimeZone="CDT" TimeZoneDesc="America/Chicago">10/01/2021
00:00</CalcDueDate>
<ReferenceNums/>
<OrderNums>
<OrderNum ShipperRef="R6000002014_10SAP" ShipmentLegID="291608671"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
</OrderNums>
</Stop>
<Stop>
<StopNumber>3</StopNumber>
<StopType>Delivery</StopType>
<Distance UOM="mi">473</Distance>
<CalcDueDate TimeZone="CDT" TimeZoneDesc="America/Chicago">10/03/2021
00:00</CalcDueDate>
<ReferenceNums/>
<OrderNums>
<OrderNum ShipperRef="R6000002014_30SAP" ShipmentLegID="291634632"
ShipmentLegSeq="1" ScheduleIntgKey="1">6000002014</OrderNum>
</OrderNums>
</Stop>
</Stops>
<DivertedOrders/>
<CompanyDefined/>
</ShipperLoadPlan>
</LeanXML>
Can anyone help me please achieve this? I appreciate any tips on this.
AFAICT, you want to do something like:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="deiveryStops" match="Stop[StopType='Delivery']" use="OrderNums/OrderNum" />
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Stop[StopType='Pickup']">
<xsl:copy>
<xsl:copy-of select="*"/>
<CopiedStop>
<xsl:copy-of select="key('deiveryStops', OrderNums/OrderNum)"/>
</CopiedStop>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This ties the "Delivery" Stops to the "Pickup" Stop based on matching OrderNum alone.
Related
I need to sum the multiplication of 2 numbers based on this example
<test>
<stop>
<id>1</id>
<unit_id>1</unit_id>
<unit_id>2</unit_id>
</stop>
<stop>
<id>2</id>
<unit_id>1</unit_id>
<unit_id>3</unit_id>
</stop>
<unit>
<id>1</id>
<count>2</count>
<value>1</value>
</unit>
<unit>
<id>2</id>
<count>4</count>
<value>1</value>
</unit>
<unit>
<id>3</id>
<count>2</count>
<value>3</value>
</unit>
The result i want to get is the one below
<test>
<stop>
<id>1</id>
<sum>6</sum>
</stop>
<stop>
<id>2</id>
<sum>10</sum>
</stop>
Any tips how to get it?
I tried with this example but the sum of the moltiplication doesn't work, it is ok for only the sum or the multiplication but not both
<xsl:template match="stop">
<xsl:variable name="ship_unit" select="id"/>
<xsl:value-of select="sum(following-sibling::unit[id=$ship_unit]/count*following-sibling::unit[id=$ship_unit]/value)"/>
If I am guessing correctly, you want to do something like:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:key name="unit" match="unit" use="id" />
<xsl:template match="/test">
<xsl:copy>
<xsl:for-each select="stop">
<xsl:variable name="unit1" select="key('unit', unit_id[1])" />
<xsl:variable name="unit2" select="key('unit', unit_id[2])" />
<xsl:copy>
<xsl:copy-of select="id"/>
<sum>
<xsl:value-of select="$unit1/count * $unit1/value + $unit2/count * $unit2/value" />
</sum>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
However, the result of applying this to your input example will be:
<?xml version="1.0" encoding="utf-8"?>
<test>
<stop>
<id>1</id>
<sum>6</sum>
</stop>
<stop>
<id>2</id>
<sum>8</sum>
</stop>
</test>
and not what you posted.
I have the below XML data as input to my XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<Application>
<Data>
<Data1>
<name>Michale</name>
<age>65</age>
<Info>
<Alias name="M">
<Contactmail>abc#gmail.com</Contactmail>
<ContactPh>8988900009</ContactPh>
</Alias>
<Alias name="Q">
<Contactmail>abc#gmail.com</Contactmail>
<ContactPh>8988900009</ContactPh>
</Alias>
</Info>
</Data1>
<Data1>
<name>Albert</name>
<age>69</age>
<Info>
<Alias name="A">
<Contactmail>xyz#gmail.com</Contactmail>
<ContactPh>89889908709</ContactPh>
</Alias>
<Alias name="P">
<Contactmail>pqr#gmail.com</Contactmail>
<ContactPh>8988988779</ContactPh>
</Alias>
</Info>
</Data1>
</Data>
</Application>
And I want to pass the Data1 block whose Alias name matches with "M", i.e.:
<Application>
<Data>
<Data1>
<name>Michale</name>
<age>65</age>
<Info>
<Alias name=M>
<Contactmail>abc#gmail.com</Contactmail>
<ContactPh>8988900009</ContactPh>
</Alias>
<Alias name=Q>
<Contactmail>abc#gmail.com</Contactmail>
<ContactPh>8988900009</ContactPh>
</Alias>
</Info>
</Data1>
</Data>
</Application>
I am stuck as to how to access an loop(ie Alias) inside a test condition?
Is there any better way to do this xslt?
<xsl:for-each select="./*[local-name() = 'Application']/*[local-name() = 'Data']">
<xsl:if test="">
....
</xsl:if>
</xsl:for-each>
The following template will do the job. The explanations are in the code.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*" /> <!-- Removes unnecessary space between elements -->
<!-- identity template --> <!-- Copies all nodes not matched by other templates -->
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<xsl:template match="Data1[Info/Alias/#name != 'M']" /> <!-- Ignores all Data1 elements which don't have an #name='M' attribute child -->
<xsl:template match="Data1[Info/Alias/#name = 'M']"> <!-- Matches all Data1 elements which have the desired child attribute -->
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Its output is:
<?xml version="1.0"?>
<Application>
<Data>
<Data1>
<name>Michale</name>
<age>65</age>
<Info>
<Alias name="M">
<Contactmail>abc#gmail.com</Contactmail>
<ContactPh>8988900009</ContactPh>
</Alias>
<Alias name="Q">
<Contactmail>abc#gmail.com</Contactmail>
<ContactPh>8988900009</ContactPh>
</Alias>
</Info>
</Data1>
</Data>
</Application>
<xsl:strip-space elements="*"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Application">
<xsl:copy>
<xsl:for-each select="Data/Data1">
<xsl:if test="Info/Alias[#name='M']">
<Data>
<Data1>
<xsl:apply-templates/>
</Data1>
</Data>
</xsl:if>
</xsl:for-each>
</xsl:copy>
</xsl:template>
You may also do like this
I have a certain requirement where, I need to move the sequence element values to another newly created element according to the the number of values in the original sequence.
Please find my Input XML and the Desired Output XML .
help is highly appreciated
Rule:
Move the value of Addr1 (catalogue/cd11/Location/Addr/Addr1) to
catalogue/cd11/Location/primary/original/Address1/place. primary/original/Address1/place need to be created.
Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.altova.com">
<publisher>
<Name id="d123">
<Place>Chicago</Place>
</Name
<catalogue id="d1" >
<cd11 id="d2">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<year>1985</year>
<Location id="d1234">
<Addr id="d234">
<Addr1 id="d565">catherine Av</Addr1>
<Addr2 id="d566">block a</Addr2>
<City id="d567">chicago</City>
</Addr>
<Addr id="d334">
<Addr1 id="d665">Illinois st</Addr1>
<Addr2 id="d666">block a</Addr2>
<City id="d667">chicago</City>
</Addr>
</Location>
</cd11>
</catalogue>
<catalogue id="d3" >
<cd11 id="d4">
<title>Jurassic World</title>
<artist>Chris Pratt</artist>
</cd11>
</catalogue>
</publisher>
</root>
Output XML:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.example.com">
<publisher>
<Name id="d123">
<Place>Chicago</Place>
</Name>
<catalogue id="d1">
<cd11 id="d2">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<year>1985</year>
<Location id="d1234">
<Addr id="d234">
<Addr1 id="d565">catherine Av</Addr1>
<Addr2 id="d566">block a</Addr2>
<City id="d567">chicago</City>
</Addr>
<Addr id="d334">
<Addr1 id="d665">Illinois st</Addr1>
<Addr2 id="d666">block a</Addr2>
<City id="d667">chicago</City>
</Addr>
<primary>
<original>
<test>test value</test>
<Address1>
<place>catherine Av</place>
</Address1>
<Address1>
<place>Illinois st</place>
</Address1>
</original>
</primary>
</Location>
</cd11>
</catalogue>
<catalogue id="d3">
<cd11 id="d4">
<title>Jurassic World</title>
<artist>Chris Pratt</artist>
</cd11>
</catalogue>
</publisher>
</root>
Thanks in advance.
You can write a template for Location elements that inserts the new elements and transforms the Addr1 elements:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xpath-default-namespace="http://www.altova.com" xmlns="http://www.altova.com">
<xsl:output indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="catalogue/cd11/Location">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
<primary>
<original>
<Address1>
<xsl:apply-templates select="Addr/Addr1" mode="convert"/>
</Address1>
</original>
</primary>
</xsl:copy>
</xsl:template>
<xsl:template match="Addr/Addr1" mode="convert">
<place>
<xsl:value-of select="."/>
</place>
</xsl:template>
</xsl:transform>
Online sample at http://xsltransform.net/ncdD7mv.
According to your comment and edit you do not want to copy the elements, instead you want to transform them to a new namespace, so you need to change all uses of xsl:copy of an element to create an element of the same local name but with the new namespace (which will simply work if you have the right xmlns="http://www.example.com" in the XSLT and use xsl:element name="{local-name()}"):
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xpath-default-namespace="http://www.altova.com" xmlns="http://www.example.com">
<xsl:output indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="#* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="catalogue/cd11/Location">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="#* | node()"/>
<primary>
<original>
<Address1>
<xsl:apply-templates select="Addr/Addr1" mode="convert"/>
</Address1>
</original>
</primary>
</xsl:element>
</xsl:template>
<xsl:template match="Addr/Addr1" mode="convert">
<place>
<xsl:value-of select="."/>
</place>
</xsl:template>
</xsl:transform>
I am trying to convert the following input XML based on grouping of qualifier but its not working and not giving me expected output.
Below is the Input XML which has to be comverted.
<document>
<item>
<gtin>1000909090</gtin>
<attrGroupMany name="foodAndBevPreparationInfo">
<row>
<attr name="preparationType">BOILING</attr>
<attrQualMany name="preparationInstructions">
<value qual="en">Prep 8</value>
<value qual="en">Prep 9</value>
<value qual="ar">Test</value>
</attrQualMany>
</row>
</attrGroupMany>
</item>
</document>
The XSLT which I am using but not giving me expected output.
XSLT:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:key name="prepmvl" match="preparationInstructions" use="concat(generate-id(..), '|', #qual)" />
<xsl:template match="document">
<CatalogItem>
<RelationshipData>
<xsl:for-each select="item/attrGroupMany[#name ='foodAndBevPreparationInfo']/row">
<Relationship>
<RelationType>Item_Master_Food_And_Bev_Prep_MVL</RelationType>
<RelatedItems count="{count(attrQualMany[#name='preparationInstructions']/value[generate-id() = generate-id(key('prepmvl', concat(generate-id(..), '|', #qual))[1])])}">
<xsl:apply-templates select="attrQualMany[#name='preparationInstructions']/value[generate-id() = generate-id(key('prepmvl', concat(generate-id(..), '|', #qual))[1])]"/>
</RelatedItems>
</Relationship>
</xsl:for-each>
</RelationshipData>
</CatalogItem>
</xsl:template>
<xsl:template match="preparationInstructions">
<RelatedItem1 referenceKey="{concat('Food_And_Bev_Prep_MVL','-',ancestor::item/gtin,'-',attr[#name='preparationType'],'-',#qual)}"/>
</xsl:template>
</xsl:stylesheet>
And the expected output should be
<?xml version="1.0" encoding="UTF-8"?>
<CatalogItem>
<RelationshipData>
<Relationship>
<RelationType>Item_Master_Food_And_Bev_Prep_MVL</RelationType>
<RelatedItems count="2">
<RelatedItem1 referenceKey="Food_And_Bev_Prep_MVL-1000909090-BOILING-en" />
<RelatedItem1 referenceKey="Food_And_Bev_Prep_MVL-1000909090-BOILING-ar" />
</RelatedItems>
</Relationship>
</RelationshipData>
</CatalogItem>
you need to change
<xsl:key name="prepmvl" match="preparationInstructions" use="concat(generate-id(..), '|', #qual)" />
to
<xsl:key name="prepmvl" match="value" use="concat(generate-id(..), '|', #qual)" />
and
<xsl:template match="preparationInstructions">
<RelatedItem1 referenceKey="{concat('Food_And_Bev_Prep_MVL','-',ancestor::item/gtin,'-',attr[#name='preparationType'],'-',#qual)}"/>
</xsl:template>
to
<xsl:template match="value">
<RelatedItem1 referenceKey="{concat('Food_And_Bev_Prep_MVL','-',ancestor::item/gtin,'-',../preceding-sibling::attr[#name='preparationType'],'-',#qual)}"/>
</xsl:template>
I would like to add an element to existing XML file with normalized value of existing element in the XML.
Any help would be extremely appreciated.
regards
<?xml version="1.0" encoding="UTF-8"?>
<top>
<Results>
<a>no</a>
<b>10</b>
<c>12</c>
<d>9</d>
</Results>
<Results>
<a>no</a>
<b>8</b>
<c>50</c>
<d>12</d>
</Results>
<Results>
<a>no</a>
<b>6</b>
<c>55</c>
<d>56</d>
</Results>
<Results>
<a>yes</a>
<b>23</b>
<c>32</c>
<d>34</d>
</Results>
</top>
In the sample input xml above, I would like to add "b_nom" elements to each of the results where the value is (b)/(minimum of 'b' grouped with a). The expected output is as below
<?xml version="1.0" encoding="UTF-8"?>
<top>
<Results>
<a>no</a>
<b>10</b>
<b_nom>1.66</b_nom>
<c>12</c>
<d>9</d>
</Results>
<Results>
<a>no</a>
<b>8</b>
<b_nom>1.33</b_nom>
<c>50</c>
<d>12</d>
</Results>
<Results>
<a>no</a>
<b>6</b>
<b_nom>1</b_nom>
<c>55</c>
<d>56</d>
</Results>
<Results>
<a>yes</a>
<b>23</b>
<b_nom>1</b_nom>
<c>32</c>
<d>34</d>
</Results>
</top>
I think you want
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="k1" match="Results" use="a"/>
<xsl:template match="#* | node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:call-template name="identity"/>
<xsl:variable name="min">
<xsl:for-each select="key('k1', ../a)">
<xsl:sort select="b" data-type="number"/>
<xsl:if test="position() = 1">
<xsl:value-of select="b"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<b_nom>
<xsl:value-of select="format-number(. div $min, '0.##')"/>
</b_nom>
</xsl:template>
</xsl:stylesheet>
Here is a changed version of the stylesheet that takes a couple of values identifying a group into account:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="http:://example.com/data"
exclude-result-prefixes="data">
<data:data xmlns="">
<group>
<key>no</key>
<values>
<value>no</value>
<value>n</value>
<value>0</value>
</values>
</group>
<group>
<key>yes</key>
<values>
<value>yes</value>
<value>y</value>
<value>1</value>
</values>
</group>
</data:data>
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="main-input" select="/"/>
<xsl:variable name="groups" select="document('')/xsl:stylesheet/data:data/group"/>
<xsl:template match="#* | node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:call-template name="identity"/>
<xsl:variable name="this" select="."/>
<xsl:variable name="min">
<xsl:for-each select="$main-input//Results[a = $groups/values[value = $this/../a]/value]">
<xsl:sort select="b" data-type="number"/>
<xsl:if test="position() = 1">
<xsl:value-of select="b"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<b_nom>
<xsl:value-of select="format-number(. div $min, '0.##')"/>
</b_nom>
</xsl:template>
</xsl:stylesheet>
That transforms the input
<?xml version="1.0" encoding="UTF-8"?>
<top>
<Results>
<a>no</a>
<b>10</b>
<c>12</c>
<d>9</d>
</Results>
<Results>
<a>n</a>
<b>8</b>
<c>50</c>
<d>12</d>
</Results>
<Results>
<a>0</a>
<b>6</b>
<c>55</c>
<d>56</d>
</Results>
<Results>
<a>yes</a>
<b>23</b>
<c>32</c>
<d>34</d>
</Results>
</top>
into the output
<top>
<Results>
<a>no</a>
<b>10</b>
<b_nom>1.67</b_nom>
<c>12</c>
<d>9</d>
</Results>
<Results>
<a>n</a>
<b>8</b>
<b_nom>1.33</b_nom>
<c>50</c>
<d>12</d>
</Results>
<Results>
<a>0</a>
<b>6</b>
<b_nom>1</b_nom>
<c>55</c>
<d>56</d>
</Results>
<Results>
<a>yes</a>
<b>23</b>
<b_nom>1</b_nom>
<c>32</c>
<d>34</d>
</Results>
</top>