473,395 Members | 1,595 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,395 software developers and data experts.

XSLT:best manner to browse a file

Hello :)

I'm newbie to XSLT and i need some advice please:

Here the action:
I have to browse an XML file with xslt :
For each node i have to determinate if it is a node where i need to add
an attribute...

The question is:
What is the best manner to browse the xml file? (prefix browse,
postfixe browse??)

an example:
THE XML FILE:
<persone>
<id>123</id>
<name>samantha</name>
<adresse>
<id>abc</id>
<roadwall street </road>
</adresse>
</personne>

THE RESULT after XSLT transformation: (i have copy the ID attribut in
the father node)

<persone id=123>
<id>123</id>
<name>samantha</name>
<adresse id=abc>
<id>abc</id>
<roadwall street </road>
</adresse>
</personne>
thanks a lot

Tachi

Dec 20 '06 #1
6 1692

na********@gmail.com wrote:
Here the action:
I have to browse an XML file with xslt :
For each node i have to determinate if it is a node where
i need to add an attribute...
It's easily done with identity transformation and exclusion
templates. By the way, the wording of your question
probably indicates that you're thinking about your problem
in terms of imperative programming. That's generally a very
bad idea when working with XSLT. You should be thinking in
terms of template matches and selecting nodesets you need,
that'll make it so much easier to figure out how you should
go about your problems.
What is the best manner to browse the xml file? (prefix
browse, postfixe browse??)
I'm not sure what you mean by prefix browse/postfix browse,
or, for that matter, what do you mean by browse where XSLT
is concerned, but as I said, using the identity
transformation seems to be the best way to solve your
problem.
THE XML FILE:
<persone>
<id>123</id>
<name>samantha</name>
<adresse>
<id>abc</id>
<roadwall street </road>
</adresse>
</personne>
That's not well-formed. It's a good idea to post examples
without obvious, easily fixable mistakes when you're asking
for help. Posting examples *with* obvious, easily fixable
mistakes is a very *bad* idea on the other hand.
<persone id=123>
<id>123</id>
<name>samantha</name>
<adresse id=abc>
<id>abc</id>
<roadwall street </road>
</adresse>
</personne>
That's, uh, even less well-formed. XML 1.0 spec clearly
states (see the AttValue definition) that attribute values
must be enclosed in either quotes or apostrophes.

The following transformation should work:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- identity transformation -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- exclusion template -->
<xsl:template match="*[id]">
<xsl:copy>
<xsl:attribute name="id">
<xsl:value-of select="id"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

--
Pavel Lepin

Dec 20 '06 #2
Hello M lepin

ho sorry for the example..

thanks a lot for your help..

i have use the identity method and adapt your XSLT.. it works now

i have a question about you code:
<xsl:template match="*[id]">
what does *[id] means please?

For information here is the worked code... thanks again:

<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"
/>

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

<!-- exclusion template -->
<xsl:template match="//THE_NODE_1_WICH_WILL_BE_ENRICH">
<xsl:copy>
<xsl:for-each select="THE_NODE_WICH_WILL_ENRICH_THE_NODE_1">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="VALUE" />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

Dec 20 '06 #3

Please quote what you're replying to. Not everyone here
is using Google Groups to read the newsgroups. The proper
etiquette is to provide some context by quoting parts of
the original post you're replying to (and only those parts)
and insert your replies under the relevant quotes.

na********@gmail.com wrote:
i have a question about you code:
<xsl:template match="*[id]">
what does *[id] means please?
You should try reading some decent XPath tutorial. In this
case *[id] means that this template matches any element
nodes that have element children named 'id'.
<!-- exclusion template -->
<xsl:template match="//THE_NODE_1_WICH_WILL_BE_ENRICH">
<xsl:copy>
<xsl:for-each
select="THE_NODE_WICH_WILL_ENRICH_THE_NODE_1">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="VALUE" />
</xsl:attribute>
</xsl:for-each>
That doesn't look too good, but, heck, whatever works for
you.
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
--
Pavel Lepin

Dec 20 '06 #4

p.*****@ctncorp.com a écrit :
<!-- exclusion template -->
<xsl:template match="//THE_NODE_1_WICH_WILL_BE_ENRICH">
<xsl:copy>
<xsl:for-each
select="THE_NODE_WICH_WILL_ENRICH_THE_NODE_1">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="VALUE" />
</xsl:attribute>
</xsl:for-each>

That doesn't look too good, but, heck, whatever works for
you.
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
ha... any suggestion will be very appreciate... why it doesn't look
good?

thanks

tachi

Dec 20 '06 #5

na********@gmail.com wrote:
p.*****@ctncorp.com a écrit :
<!-- exclusion template -->
<xsl:template
match="//THE_NODE_1_WICH_WILL_BE_ENRICH">
<xsl:copy>
<xsl:for-each
select="THE_NODE_WICH_WILL_ENRICH_THE_NODE_1">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="VALUE" />
</xsl:attribute>
</xsl:for-each>
That doesn't look too good, but, heck, whatever works
for you.
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>

ha... any suggestion will be very appreciate... why it
doesn't look good?
It's hard to tell whether there's anything wrong with the
code without a real example (the above is pseudo-codish if
I got that right), but, generally, for-each in neophytes'
code is a bad sign. It seems to denote that they're
thinking about their transformations in inappropriate
terms.

XSLT is a functional language at heart, and it simply
doesn't work all that well if you're trying to use it
imperatively. It's not even the question of conceptual
purity,--whatever works, as I said,--it's just that
approaching problems the same way you did while coding in
C++/Java/Perl/PHP/{imperative language of your choice}
tends to lead you down a lot of blind alleys. Getting the
right mindset from the start seems to help a lot.

--
Pavel Lepin

Dec 21 '06 #6
Hello M lepin ,

I see...

i'm going to change my "programming" reflexion into an "xml" one ..

thanks a lot for your advices...

++

tachi

p.*****@ctncorp.com a écrit :
na********@gmail.com wrote:
p.*****@ctncorp.com a écrit :
<!-- exclusion template -->
<xsl:template
match="//THE_NODE_1_WICH_WILL_BE_ENRICH">
<xsl:copy>
<xsl:for-each
select="THE_NODE_WICH_WILL_ENRICH_THE_NODE_1">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="VALUE" />
</xsl:attribute>
</xsl:for-each>
>
That doesn't look too good, but, heck, whatever works
for you.
>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
ha... any suggestion will be very appreciate... why it
doesn't look good?

It's hard to tell whether there's anything wrong with the
code without a real example (the above is pseudo-codish if
I got that right), but, generally, for-each in neophytes'
code is a bad sign. It seems to denote that they're
thinking about their transformations in inappropriate
terms.

XSLT is a functional language at heart, and it simply
doesn't work all that well if you're trying to use it
imperatively. It's not even the question of conceptual
purity,--whatever works, as I said,--it's just that
approaching problems the same way you did while coding in
C++/Java/Perl/PHP/{imperative language of your choice}
tends to lead you down a lot of blind alleys. Getting the
right mindset from the start seems to help a lot.

--
Pavel Lepin
Dec 21 '06 #7

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

Similar topics

2
by: Richard L Rosenheim | last post by:
Is it possible to include addition tags in a XSLT file, that the XSLT processor will, for all practical purposes, ignore? What I'm looking to do is to include a section to contain information...
0
by: Ganesh Kolappan via .NET 247 | last post by:
Hi I am trying to populate a <asp:dropdownlist> in a XSLT file withdatasource pointing to a C# codebehind file method which returnsa dataview. I am using XSLT extension object. But I am...
4
by: Isambella via DotNetMonster.com | last post by:
Hi, I have in a string some XML and I want that xml to be transformed using XSLT file (I found the way how to transform a xml file using XSLT but I didn’t find a way how to transform using...
1
by: Max Evans | last post by:
I have a XML file, which contains itemid-elements, e.g.: <itemid>3</itemid> <itemid>12</itemid> Now I want to convert these IDs to the corresponding name via XSLT. I thought I could do it this...
1
by: vinki | last post by:
Hi Everyone, I have this xslt file. I want to print the page directly to the printer after every MOP template is matched. So for example the ouput is coming to the HTML page like this ...
4
by: =?Utf-8?B?dmlua2k=?= | last post by:
I just want to pass the below URL in my xslt file. <a href="http://testwebi/testlite/admin/remoteMgmt.aspx?id=<xsl:value-of select="indexID"/>&action=1"> i keep geeting errors whn i am trying...
1
by: Shrek | last post by:
My xslt file contains a passed parameters <xsl;param name="Widths">70px,70px,70px,100px,100px</xsl;param> which I want to use to sets the widths of my table columns . when I create my...
2
by: ismailc | last post by:
Hi, I need help please! My tooltip works fine but the moment one reload the page which is set on some objects then the tooltip does not work! How can i bypas this or make it reload the xslt...
1
by: suratna | last post by:
i have an xslt file. i have no problem writing html code inside it but when i write a mysql select query inside it, it gives error. Is there any way to write php code inside xslt file? ratna
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
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,...
0
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 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.