XML to XML using XSL

@

@do

Hi!

My XML File is something like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<item_list>
<item_list_elements>
<code>01600</code>
<name>John</name>
<text>some text ABC</text>
</item_list_elements>
<item_list_elements>
<code>01600</code>
<name>Smith</name>
<text>another text</text>
</item_list_elements>

...

</item_list>

I need to change <code> values in this file using XSL and produce same
XML structure as output.
Conditions are: if <text> contains "ABS" and <code> = 01600 then code
= "02600"

Output scould be:
<?xml version="1.0" encoding="ISO-8859-1"?>
<item_list>
<item_list_elements>
<code>02600</code>
<name>John</name>
<text>some text ABC</text>
</item_list_elements>
<item_list_elements>
<code>01600</code>
<name>Smith</name>
<text>another text</text>
</item_list_elements>
...
</item_list>

Thanks for all help.
Ado
 
A

Andy Dingley

@do said:
I need to change <code> values in this file using XSL and produce same
XML structure as output.
Conditions are: if <text> contains "ABS" and <code> = 01600 then code
= "02600"

Take the "identity transform" stylesheet (just search for it, you'll
find it) and then subclass the behaviour you need to change. Add
another template rule that matches only the element you need to change
and outputs the modified form.
 
P

p.lepin

@do said:
My XML File is something like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<item_list>
<item_list_elements>
<code>01600</code>
<name>John</name>
<text>some text ABC</text>
</item_list_elements>
<item_list_elements>
<code>01600</code>
<name>Smith</name>
<text>another text</text>
</item_list_elements>
</item_list>

I need to change <code> values in this file using XSL and
produce same XML structure as output.
Conditions are: if <text> contains "ABS"...

'ABC', I suppose.
...and <code> = 01600 then code = "02600"

Well, have you tried to solve this problem yourself? This
is quite trivial, you know, and even if you couldn't come
up with a solution, you would get a much more friendly
welcome if you had some code to show.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput
method="xml"
version="1.0"
encoding="UTF-8"/>
<!-- identity transformation -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- our special case -->
<xsl:template
match="
item_list_elements
Code:
[contains(text,'ABC')]">
    <xsl:copy>
      <code>02600</code>
      <xsl:apply-templates
        select="@*|node()[name()!='code']"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top