Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 5th, 2008, 03:08 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml to xml using xslt

Hi, iam very new to xslt. I need to transform a xml file into another format of xml file, and i only want to display certain contents from the 1st xml file. However, i keep having all the inputs from the 1st xml file. Can anyone help me identify my mistake?

[u]The first xml file</u>
<?xml version="1.0" encoding="UTF-8"?>
<labb xmlns="http://www.*************">
    <header>
        <version>1.2</version>
        <lab>
            <appointed>2</appointed>
            <id>QUEEE</id>
            <name>LL</name>
            <addr>
                <BlkNo>88</BlkNo>
                <StreetName>c</StreetName>
                <FloorNo>00</FloorNo>
                <UnitNo>77</UnitNo>
                <BuildingName>Wonderful land</BuildingName>
                <PostalCode>888888</PostalCode>
            </addr>
            <CMSCode>TTT</CMSCode>
        </lab>
        <clinic>
            <id>cln007</id>
            <name>test clinic</name>
        </clinic>
        <clinic_lab>
            <id>DS011</id>
            <name>test clinic</name>
        </clinic_lab>
        <order_submit_dt>20070908</order_submit_dt>
        <order_status_code>CM</order_status_code>
        <order_control_code>NW</order_control_code>
        <orderby>
            <id>NC</id>
            <name>TEST</name>
        </orderby>
        <priority/>
        <result_dt>20070908163003</result_dt>
        <result_msg_control>ooo</result_msg_control>
        <profile_code_list>X105482</profile_code_list>
        <profile_desc_list>BASIC(GLL)</profile_desc_list>
    </header>
    <patient>
        <name>SAMPLE TESTINg</name>
        <identity>XXX2494221</identity>

        <race>cc</race>
        <dob>19710101</dob>
        <birthYear>
            <YearOfBirth>1988</YearOfBirth>
        </birthYear>

    </patient>
</labb>


[u]
The output xml file is something like the following:
</u>
<?xml version="1.0" encoding="utf-8"?>
<Request>
<Client>
        <ClientName>Client Name 01</ClientName>
        <ClientRace>C</ClientRace>
        <ClientGender>F</ClientGender>
        <ClientNRIC>S1234567D</ClientNRIC>
</Client>
<Clinic>
        <Appointed>2</Appointed>
        <ClinicName>Clinic Name 01</ClinicName>
</Clinic>


[u]And I have written a xslt file</u>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="no" standalone="no" indent="yes" />

    <xsl:template match="/">
        <Request>
            <xsl:apply-templates ></xsl:apply-templates>
        </Request>
    </xsl:template>

    <xsl:template match="/patient">
        <ClientData>
            <ClientName>

              <xsl:value-of select="name"/>

            </ClientName>
            <ClientRace>
                <xsl:value-of select="race" />
            </ClientRace>
            <ClientGender>
                <xsl:value-of select="****" />
            </ClientGender>
</ClientData>
</xsl:template>

</xsl:stylesheet>

 Thanks.

Reply With Quote
  #2 (permalink)  
Old August 5th, 2008, 03:29 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Change match="/patient" to match="patient". The "/patient" form would only match if the patient is the outermost element of the document, which in your case it isn't.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old August 5th, 2008, 04:00 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply but I have tried that, and still having the same problem.

Reply With Quote
  #4 (permalink)  
Old August 5th, 2008, 04:33 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, I usually only spot one bug at a time when inspecting source code. The next bug (I don't guarantee it is is the last) is that your source document contains elements that are in a namespace, but you are trying to match elements in no namespace. Your stylesheet needs to declare the namespace

xmlns:p="http://www.*************"

and then use this prefix when referring to elements in the source documetn, for example match="p:patient"

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old August 5th, 2008, 05:10 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks..ya, i know it has many bugs. Been struggling to do this. Anyway, i used to delcare the namespace in the sylesheet, but i used "p/patient" instead of p:patient.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
XSLT read through XML to transform another XML dendenx2 XSLT 8 July 7th, 2005 08:18 PM
XSLT for complicated xml to xml transf. required doug@sirvisetti XSLT 3 June 17th, 2005 04:26 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM



All times are GMT -4. The time now is 04:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.