hi,
I have a xml in which I want to replace the element(s) value with XSLT
Xml message <Message> -
<case>
-
<party1>
-
<!-- there are other elements -->
-
<notes id="1">abcd</notes>
-
<notes id="2">abcd</notes>
-
<notes id="3">abcd</notes>
-
-----
-
-
<notes id=n>some text</notes>
-
</party1>
-
-
<party2>
-
<!-- there are other elements -->
-
<notes id="1">abcd</notes>
-
<notes id="2">abcd</notes>
-
<notes id="3">abcd</notes>
-
-----
-
-
<notes id=n>some text</notes>
-
</party2>
-
-
<client1>
-
-
<!-- there are other elements -->
-
<notes id="1">abcd</notes>
-
<notes id="2">some text</notes>
-
<notes id="3">some text</notes>
-
-----
-
-
<notes id="n">some text</notes>
-
-
</client1>
-
-
<client2>
-
-
<!-- there are other elements -->
-
<notes id="1">some text</notes>
-
<notes id="2">some text</notes>
-
<notes id="3">some text</notes>
-
-----
-
-
<notes id="n">some text</notes>
-
-
</client2>
-
-
-
</case>
-
</Message>
From the above xml I want to copy all the elements to another xml but, I want to modify the values <notes> element to some other value.
I have managed to construct a XSL like this.
XSL : - <?xml version='1.0' encoding='ISO-8859-1'?>
-
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
<xsl:output method="xml" indent="yes"/>
-
<xsl:strip-space elements="*"/>
-
<xsl:key name="nvalue" match="notes" use="text()"/>
-
-
<xsl:template match="node()">
-
<xsl:copy>
-
<xsl:copy-of select="@*"/>
-
<xsl:apply-templates select="node()"/>
-
</xsl:copy>
-
</xsl:template>
-
-
<xsl:apply-templates select="notes"/>
-
-
<xsl:template match="notes">
-
<notes>replace notes</notes>
-
</xsl:template>
-
-
</xsl:stylesheet>
please help me with the XSL
Many thanks in advance
4 29220
What's the problem? It's working as you intend (...once you correct the xml (it's not well-formed)—put the attribute values in quotes)
regards
Well, from your code you'd be missing the id attributes on notes nodes. Is that the problem?
Could change your notes template accordingly. -
<xsl:template match="notes">
-
<xsl:copy>
-
<xsl:copy-of select="@*"/>
-
<xsl:text>replace notes</xsl:text>
-
</xsl:copy>
-
</xsl:template>
-
<xsl:copy-of select="@*"/> is the line that would copy the id attributes.
Thank you very much for point it out !! Yes I'm missing the @ attribute template. I have corrected it. like this. - <?xml version="1.0"?>
-
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
<xsl:template match="*">
-
<xsl:copy>
-
<xsl:apply-templates select="@*|*|text()"/>
-
</xsl:copy>
-
</xsl:template>
-
<xsl:template match="notes">
-
<notes><xsl:apply-templates select="@*"/>replaced Value</notes>
-
</xsl:template>
-
-
<xsl:template match="@*|text()">
-
<xsl:copy/>
-
</xsl:template>
-
-
</xsl:stylesheet>
But, I'm getting another issue it not working on the xml on which I intend to work
please let me know if changes for my XSL on below XML
you have to add the xml namespace to your xsl. - <?xml version="1.0"?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-
xmlns:mskichu="somexsd"
-
xmlns="somexsd">
note: if this still doesn't work, you have to add the namespace prefix to your XPath expressions.
on the other hand, if you need the namespace for xsd validation, define it as xmlns:xsd (not as default namespace).
regards
Sign in to post your reply or Sign up for a free account.
Similar topics
by: AA |
last post by:
Hello, I need to extract an element from a xml document something like this
<myXml>
<Header>
<Name/>
<LastName/>
<Age/>
</Head>
<Body>
<Properties>
|
by: Martin |
last post by:
Hi,
I have a xml file like the one below
<?xml version="1.0" encoding="utf-8"?><e1
xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2"
e1:rest="345"/>
If I try to create a...
|
by: Rick |
last post by:
I have an XML document that is generated from Infopath, I need to change
the value of a namespace that is defined in a node in the form:
<xsf:xDocumentClass "xmlns:my=valuehere">.
when i navigate...
|
by: nospam |
last post by:
I'm trying to transform an xml file that contains empty short elements like
the following:
<element attrib="abc"/>
using the XmlTransform class. But I cannot seem to preserve the short format...
|
by: ina |
last post by:
Hello all,
I am newbie in xml and have a problem with this parse.
I have this xml.file
<Style>
<Strategy>
|
by: tschwartz |
last post by:
I have an xml document in which elements are hierarchically related to
eachother conceptually. Unfortunately, the hierarchical relationship
is not modelled in the schema (i.e., the elements are...
|
by: Andy Dingley |
last post by:
>From a thread over in c.i.w.a.h
"RFC: From XHTML to HTML via XSLT"
http://groups.google.co.uk/group/comp.infosystems.www.authoring.html/msg/f112c230061ffe86
As is well-known, the XSLT HTML...
|
by: kluge.wolfram |
last post by:
Hi,
i get stucked on a transformation problem using XSLT. What i need is
to copy an XML Tree to an output XML without any automatic changes.
Since i used <xsl:copyor <xsl:copy-ofthere occur...
|
by: John Larson |
last post by:
Hi All,
I am some information from INSPEC database records in XML to build a
relational database of my own. I am currently trying to extract information
by doing an XSLT transform of the XML...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
| |