473,811 Members | 3,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:styleshe et 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>
<Nomenclature s>
</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:attribut e name="value">
<xsl:value-of select="@REF"/>
</xsl:attribute>
</xsl:element>
<AxisY name="STS_INDIC ATOR">
<xsl:element name="Position" >
<xsl:attribut e 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:attribut e name="value">
<xsl:value-of
select="@TIME_P "/>
</xsl:attribute>
</xsl:element>
<xsl:element name="Cell">
<xsl:attribut e name="value">
<xsl:value-of
select="@OBS_VA LUE"/>
</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 1881
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
16661
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
4038
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 to use any of these, or can any XML-aware software (parser/validator or xsl- enginge) use any of these?
1
2047
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 following sample document: <root> <a b="1" />
1
1483
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
1273
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 kind of books for XSLT. Cheers! =) ..Andreas
9
2157
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 should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
3
1919
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). There are lots of Google hits on each of these specifications and related technology, shuch as namespaces but there's almost nothing I can find that shows useful examples of the different ways they might be combined?
1
2421
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 stylesheets, that generates .NET assemblies) 2. Performance improvements in the XslCompiledTransform
0
9734
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10397
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10138
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9214
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7674
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3027
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.