473,566 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>samanth a</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>samanth a</name>
<adresse id=abc>
<id>abc</id>
<roadwall street </road>
</adresse>
</personne>
thanks a lot

Tachi

Dec 20 '06 #1
6 1704

na********@gmai l.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>samanth a</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>samanth a</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:styleshe et 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:attribut e 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:styleshe et 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_NOD E_WICH_WILL_ENR ICH_THE_NODE_1" >
<xsl:attribut e 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********@gmai l.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_NOD E_WICH_WILL_ENR ICH_THE_NODE_1" >
<xsl:attribut e 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_NOD E_WICH_WILL_ENR ICH_THE_NODE_1" >
<xsl:attribut e 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********@gmai l.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_NOD E_WICH_WILL_ENR ICH_THE_NODE_1" >
<xsl:attribut e 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 "programmin g" reflexion into an "xml" one ..

thanks a lot for your advices...

++

tachi

p.*****@ctncorp .com a écrit :
na********@gmai l.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_NOD E_WICH_WILL_ENR ICH_THE_NODE_1" >
<xsl:attribut e 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
1452
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 regarding what parameters the XSLT file is expecting. Then my program can retrieve the information from the style sheet and prompt the user for the...
0
3199
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 getting"The 'DataSource' property is set only by the runtime. It cannotbe declared." error code: <?xml version="1.0"?> <xsl:stylesheet...
4
3497
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 string) Help me pls thx in advance Isambella
1
1349
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 way (XSLT): <xsl:apply-templates select="itemid" /> <xsl:template match="itemid"> <xsl:value-of select="itemnames" /> </xsl:template> And I'd like...
1
3820
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 Phone: (909) 549-3419
4
8724
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 to pass this url, but if i change the url to below url <a href="http://testwebi/testlite/admin/remoteMgmt.aspx?id=12/>&action=1">
1
2503
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 table I make the following call. <tr> <th valign="bottom" width="{foo:GetWidth(0)}">Length<br/>(units)</th>
2
2234
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 file? <xsl:if test="Tooltip != ''"> <a> <xsl:attribute name='href'>#</xsl:attribute> <xsl:attribute...
1
4418
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
7666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
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 we have to send another system
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.