I need XSLT to transform:
<?xml version="1.0" encoding="UTF-8"?>
<LineItems>
<Quantity>
<Quantity0000>1</Quantity0000>
<Quantity0001>2</Quantity0001>
</Quantity>
<Description>
<Description0000>Description1</Description0000>
<Description0001>Description2</Description0001>
</Description>
</LineItems>
to:
<?xml version="1.0" encoding="UTF-8"?>
<LineItems>
<LineItem>
<Quantity>1</Quantity>
<Description>Description1</Description>
</LineItem>
<LineItem>
<Quantity>2</Quantity>
<Description>Description2</Description>
</LineItem>
</LineItems>
Note that while my example only has 2 line items there may be any
number of them.
I realize this source XML is horribly designed but that is out of my
control (and the reason I want to transform it in the first place). 3 1136
Suggestion: Set a variable to hold the new node name, then select new
node(s) based on this value.
e.g.: <xsl:varibale name="nQ" select="substring-after(name(),
'Quantity')" />
<xsl:value-of select="//*[name()='$nQ']"/>
Thanks Kryptomoon. I've tried this and still get it to work. This is
my current XSL:
<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:template match="LineItems">
<LineItems>
<xsl:call-template name="loopMe">
<xsl:with-param name="counter" select="0"/>
<xsl:with-param name="max" select="count(Quantity/*)"/>
</xsl:call-template>
</LineItems>
</xsl:template>
<xsl:template name="loopMe">
<xsl:param name="counter"/>
<xsl:param name="max"/>
<xsl:if test="$counter < $max">
<xsl:variable name="quantity" select="concat('Quantity',
format-number($counter, '0000'))"/>
<xsl:variable name="description" select="concat('Description',
format-number($counter, '0000'))"/>
<LineItem>
<Quantity>
<xsl:value-of select="//*[name()='$quantity']"/>
</Quantity>
<Description>
<xsl:value-of select="//*[name()='$description']"/>
</Description>
</LineItem>
<xsl:call-template name="loopMe">
<xsl:with-param name="counter" select="$counter + 1"/>
<xsl:with-param name="max" select="$max"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The output is formatted correctly but does not contain any of the
values:
<?xml version="1.0" encoding="UTF-8"?>
<LineItems>
<LineItem>
<Quantity></Quantity>
<Description></Description>
</LineItem>
<LineItem>
<Quantity></Quantity>
<Description></Description>
</LineItem>
</LineItems>
Anyone have any thoughts? Thanks.
Nevermind. it was the single-quotes around the variable references. If
I remove those it works!
<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:template match="LineItems">
<LineItems>
<xsl:call-template name="loopMe">
<xsl:with-param name="counter" select="0"/>
<xsl:with-param name="max" select="count(Quantity/*)"/>
</xsl:call-template>
</LineItems>
</xsl:template>
<xsl:template name="loopMe">
<xsl:param name="counter"/>
<xsl:param name="max"/>
<xsl:if test="$counter < $max">
<xsl:variable name="quantity" select="concat('Quantity',
format-number($counter, '0000'))"/>
<xsl:variable name="description" select="concat('Description',
format-number($counter, '0000'))"/>
<LineItem>
<Quantity>
<xsl:value-of select="//*[name()=$quantity]"/>
</Quantity>
<Description>
<xsl:value-of select="//*[name()=$description]"/>
</Description>
</LineItem>
<xsl:call-template name="loopMe">
<xsl:with-param name="counter" select="$counter + 1"/>
<xsl:with-param name="max" select="$max"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jblazi |
last post by:
Let us assume I have a list like
and would like to transoform it into the string
'{1,2},{7,8},{12,13}'
Which is the simplest way of achiebing this? (The list is in fact much
longer and...
|
by: Alastair Cameron |
last post by:
I have a VB (VB6, not .NET) application that reads an XML file (using MSXML
v3.2 parser); the XML file contains a reference to an external DTD.
The DTD has numerous enumerated attribute...
|
by: Jody Greening |
last post by:
Transforming with XSLT, Grouping elements until difference found.
I am seeking some help with the following problem, I am fairly new at
XSLT transformations, and my problem may lie in looking at...
|
by: kelvSYC |
last post by:
Is there an efficient way to check whether an enumerator exists when
casting an integer into an enumerated value?
For example, say I have this:
enum MyEnum {
a = 1,
b = 2,
// more arbitrary...
|
by: Claire |
last post by:
Is there an easy way to return the number of elements in an enumerated type
please
thanks
Claire
|
by: Brandon |
last post by:
Hello all, and thanks for taking a look at this.
First off, the project I am working on is a server/client
application that contains a shared assembly of common
classes between the two...
|
by: Ben Finney |
last post by:
Howdy all,
I've recently packaged 'enum' in PyPI. In its description, I make the
claim that it creates "immutable" enumeration objects, and that the
enumeration values are "constant" values.
...
|
by: Jakub.Bednarczuk |
last post by:
Hallo everybody
I have the problem with getting attributes values and also attributes
names. I am reading an xml file with DOM. Lets see an example:
file I read
<root>
<Def></Def>...
|
by: David Mathog |
last post by:
Is there a standard compliant method to access the number of elements in
an enumerated type in C, either from within the preprocessor or the
running program?
The example below compiles and runs...
|
by: james_027 |
last post by:
hi,
i have a list from a resultset like this
1,"Chicago Bulls",,,""
2,"Cleveland Caveliers",,,""
4,"Detroit Pistons",1,"23686386.35"
4,"Detroit Pistons",2,"21773898.07"
4,"Detroit...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |