473,396 Members | 2,090 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,396 software developers and data experts.

Xpath and XSLT-transformation problem

Hi All,

Currently I am trying to convert one xml file into another xml file
which having different format than original xml file.

my input xml file is like:

<?xml version="1.0" encoding="UTF-8"?>
<MyData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:n1="http://www.abc.com/resources/XML/schemas/v2_0">

<header>
<id>1</id>
<test>xyz</test>
</header>
<n1:DataSet>
<n1:Group REF="SE" ADJ="N"
ABC_I="PROD" ABC_A="N100C0" ABC_IN="1"
ABC_B_Y="2000"/>
<n1:Series FR="M" REF="SE" ADJ="N"
ABC_I="PROD" ABC_A="N100C0" ABC_IN="1"
ABC_B_Y="2000">
<n1:Obs TIME_P="199001" OBS_VALUE="101.2"/>
<n1:Obs TIME_P="199002" OBS_VALUE="103.2"/>
<n1:Obs TIME_P="199003" OBS_VALUE="105.2"/>
<n1:Obs TIME_P="199004" OBS_VALUE="107.2"/>
</n1:Series>
</n1:DataSet>
</MyData>

I have to extract the Series element based on the values of ADJ,ABC_A
etc.My intend is more clear from the following xsl file:
The problem is that in xpath expression it doesn't recognizing
namespace elements ie elements prefixed with n1

Please check this and let me know where i am doing wrong.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:n1="http://www.abc.com/resources/XML/schemas/v2_0">

<xsl:output method="xml" encoding="UTF-8" indent="yes"/>

<xsl:param name="REF"/>
<xsl:param name="ADJ"/>
<xsl:param name="ABC_I"/>
<xsl:param name="ABC_A"/>
<xsl:param name="ABC_IN"/>
<xsl:param name="ABC_B_Y"/>
<xsl:template match="/">

<Data>
<Table language="en">
<Info>
</Info>
<Nomenclatures>
</Nomenclatures>
<Context>
<Selector type="theme" code="theme1"/>
<Selector type="domain" code="euro"/>
<Selector type="table" code="bp_q"/>
</Context>
<Grid>

<AxisZ name="REF">
<xsl:for-each
select="MyData/n1:DataSet/n1:Series[
@ADJ=$ADJ and
@ABC_A=$ABC_A and
@ABC_IN=$ABC_I and
@ABC_B_Y=$ABC_B_Y]">
<xsl:element name="Position">
<xsl:attribute name="value">
<xsl:value-of select="@REF"/>
</xsl:attribute>
</xsl:element>
<AxisY name="STS_INDICATOR">
<xsl:element name="Position">
<xsl:attribute name="value">
<xsl:value-of select="@ABC_IN"/>
</xsl:attribute>
</xsl:element>
<AxisX name="time">
<xsl:for-each select="./n1:Obs">
<xsl:element name="Position">
<xsl:attribute name="value">
<xsl:value-of
select="@TIME_P"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="Cell">
<xsl:attribute name="value">
<xsl:value-of
select="@OBS_VALUE"/>
</xsl:attribute>
</xsl:element>
</xsl:for-each>
</AxisX>
</AxisY>
</xsl:for-each>
</AxisZ>
</Grid>

</Table>
</Data>
</xsl:template>
</xsl:stylesheet>

Thanks and Regards,
Pathik

Mar 30 '07 #1
1 1862
On Mar 30, 8:26 am, "Pathik" <gandhi.pat...@gmail.com>
wrote:
my input xml file is like:
[skipped]
My intend is more clear from the following xsl file:
You've gotta be kidding. You're using 8 spaces for
indentation and you've obviously never heard of the 78
chars rule. Worse yet, this is a brilliant example of how
NOT to write XSL transformations. The thing is horrible and
you think it makes anything 'more clear'?
The problem is that in xpath expression it doesn't
recognizing namespace elements ie elements prefixed with
n1
Wonderful. What makes you think that?
<xsl:for-each
select="MyData/n1:DataSet/n1:Series[
@ADJ=$ADJ and
@ABC_A=$ABC_A and
@ABC_IN=$ABC_I and
@ABC_B_Y=$ABC_B_Y]">
I would strongly recommend learning some basic debugging
techniques. (Hint: there's an error in this bit of code.)

(Note: looking at awful code and pointing straight at the
bug is something I normally charge for on per-hour basis.
You get answers to smart and thought-provoking questions
for free; do not expect people to do your bloody job for
you. Keep that in mind.)

--
Pavel Lepin

Mar 30 '07 #2

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

Similar topics

7
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
1
by: DV | last post by:
Hello, can anyone tell me or point me to somewhere what the exact differences (in terms of when would I use what) between XPath, XLink, XPointer and DOM are? Does it require special software...
1
by: inquirydog | last post by:
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt? document("document.xml")//a/@b For the...
1
by: Sonu Kapoor | last post by:
Hi, I would like to use xpath with xslt. I know that this should be possible, but I dont get it ! Here is what I have tried so far: ==================================== my xml file:...
1
by: Andreas Håkansson | last post by:
Hello, Does anyone have any advice on a good XPath book? Perhaps two books, one at a beginners/intermediate level and one advanced. While on the subject I wouldn't mind some advice on the same...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
3
by: Greg | last post by:
Hi, I want to create a web based interface that uses a form + Javascript (in an XHTML namespace) to construct an XPath to query and modify the attributes of some SVG (in an SVG namespace). ...
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
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:
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
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
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.