473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Change node:child in attributes

ina
Hello all,

I have this xml file:

<FS>
<Style>
<Name>Luca</Name>
<Strategy>
<Strategy_Style>Geo\Asia</Strategy_Style>
<Strategy_Style>Geo\America</Strategy_Style>
<Strategy_Style>Geo\Europe</Strategy_Style>
<Strategy_Style>Sector\America/Cash</Strategy_Style>
</Strategy>
</Style>
<Style>

<Name>George</Name>
<Strategy>
<Strategy_Style>Geo\Asia</Strategy_Style>
<Strategy_Style>Geo\America</Strategy_Style>
<Strategy_Style>Geo\Europe</Strategy_Style>
<Strategy_Style>Sector\America/Cash</Strategy_Style>
</Strategy>
</Style>
</FS>

To have this as output after parsing
<Name>George</Name>
<Strategy>
<Geo Asia = 'yes' America = 'yes' Europe = 'yes'/>
<Sector America/Cash ='yes'/>
</Strategy>

any Suggestions to follow?

Ina

Jun 13 '06 #1
3 1457
On Tue, 13 Jun 2006 12:54:04 +0200, ina <ro*************@gmail.com> wrote:
Hello all,

I have this xml file:

<FS>
<Style>
<Name>Luca</Name>
<Strategy>
<Strategy_Style>Geo\Asia</Strategy_Style>
<Strategy_Style>Geo\America</Strategy_Style>
<Strategy_Style>Geo\Europe</Strategy_Style>
<Strategy_Style>Sector\America/Cash</Strategy_Style>
</Strategy>
</Style>
<Style>

<Name>George</Name>
<Strategy>
<Strategy_Style>Geo\Asia</Strategy_Style>
<Strategy_Style>Geo\America</Strategy_Style>
<Strategy_Style>Geo\Europe</Strategy_Style>
<Strategy_Style>Sector\America/Cash</Strategy_Style>
</Strategy>
</Style>
</FS>

To have this as output after parsing

<Name>George</Name>
<Strategy>
<Geo Asia = 'yes' America = 'yes' Europe = 'yes'/>
<Sector America/Cash ='yes'/>
</Strategy>

any Suggestions to follow?


Although I cannot disagree with Andy's analysis, I cannot supress my
desire to tackle any XSLT problem I encounter:-)

<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="primary" match="Strategy_Style"
use="concat(substring-before(.,'\'),generate-id(..))"/>
<xsl:template match="Strategy">
<xsl:for-each
select="Strategy_Style[generate-id()=generate-id(key('primary',concat(substring-before(.,'\'),generate-id(..)))[1])]">
<xsl:element name="{substring-before(.,'\')}">
<xsl:apply-templates
select="key('primary',concat(substring-before(.,'\'),generate-id(..)))"/>
</xsl:element>
</xsl:for-each>
</xsl:template>

<xsl:template match="Strategy_Style">
<xsl:attribute
name="{translate(substring-after(.,'\'),'/\','_')}">yes</xsl:attribute>
</xsl:template>

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

What this stylesheet does:

By default, alle elements and atributes are copied. This is achieved with
the 'identity transform' template:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>

When a 'Strategy' element is encountered, the alorithm creates one element
for each unique pre-slash value in the 'Strategy_Style' children (Uses
muenchian grouping). Once the element is created, it is populated with
attributes by the 'Strategy_Style' template.

--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«Η αλήθεια και το λάδι πάντα βγαίνουν από πάνω»
Jun 13 '06 #2
ina wrote:
any Suggestions to follow?


Have your XML application re-designed by someone who knows what they're
doing.

By the looks of this, you're trying to build some real business
application _and_ learn the very basics of XML at the same time. That
just isn't a strategy that can end well -- you might even learn some
XML by doing it, but the live application is hardly the right place to
be learning this stuff. If there's a risk that you're making long-term
choices that you're going to have to live with for an appreciable time,
then someone doing their very first steps in XML just isn't the right
person to be architecting things.

To be specific, the XML schema here sucks. Forget about how you process
it, with a million little script fragments and XSLT transforms, you
need to have an underlying schema that works for the business and is
long-term supportable. This one isn't.

Please don't take this the wrong way - as an XML and XSLT student
you're doing great. But I'm concerned that your boss has also thrown
you at this problem and is expecting you to do work you're just not
trained for yet.

Jun 13 '06 #3
ina
Thank you for this explanation Andy.

First of all, I am learning xml, yes it is true but you do not know
what i am doing with it you even do not know it is the purpose of that
and of which kind of business are you speak for?

and just ask for any suggestions how to transform xml schema and
another one, that 's all.

Thank you for the answers.

Ina
Andy Dingley <di*****@codesmiths.com> wrote:
ina wrote:
any Suggestions to follow?


Have your XML application re-designed by someone who knows what they're
doing.

By the looks of this, you're trying to build some real business
application _and_ learn the very basics of XML at the same time. That
just isn't a strategy that can end well -- you might even learn some
XML by doing it, but the live application is hardly the right place to
be learning this stuff. If there's a risk that you're making long-term
choices that you're going to have to live with for an appreciable time,
then someone doing their very first steps in XML just isn't the right
person to be architecting things.

To be specific, the XML schema here sucks. Forget about how you process
it, with a million little script fragments and XSLT transforms, you
need to have an underlying schema that works for the business and is
long-term supportable. This one isn't.

Please don't take this the wrong way - as an XML and XSLT student
you're doing great. But I'm concerned that your boss has also thrown
you at this problem and is expecting you to do work you're just not
trained for yet.


Jun 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ted | last post by:
Hello, I'm trying to copy a node and all its descendants and also change all the id attributes. <book> <chapter id="c1"> <verse id="v1">Hello World</verse> <verse id="v2">Goodbye...
4
by: Alex | last post by:
It seems that XML Serializatoin automatically puts certain XSD attributs in the root node. How can I control the root node attributes emitted to something more custom so I can preserve my schema...
1
by: jaloplo | last post by:
Hi, I'm having a big problem cause I need to write attributes values without knowing the name of these attributes. For example, my xml file is like this: <element id="1" name="pepe"...
0
by: saravanaVijayakumar | last post by:
I'm new to xml .. I had created a application such a way that I have to display the xml file in treeview control in C#.Net Application ... If I select the particular Node it should display the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.