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 January 29th, 2007, 11:41 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Missing Node (Node data)

Hi All
Sorry if this is obvious to you.
I've been using xslt for two days now and I am stuck.

I have some xml as below
<?xml version="1.0"?>
<rdf:RDF
    xmlns:db="http://localhost:2020/resource/"
    xmlns:omap="file:///C:/d2r-server-0.3.1/outlookmap.ttl#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:emap="file:///C:/d2r-server-0.3.1/eudoramap.ttl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:out="http://localhost:2020/resource/outlook/"
    xmlns:eud="http://localhost:2020/resource/eudora/">
  <eud:ENTRIES rdf:about="http://localhost:2020/resource/ENTRIES/Diane/Barnes">
    <eud:ENTRIES_WORKWEBADDRESS>http://www.landamericafinancial.com </eud:ENTRIES_WORKWEBADDRESS>
    <eud:ENTRIES_FULLNAME>Diane Barnes</eud:ENTRIES_FULLNAME>
    <eud:ENTRIES_WORKORGANIZATION>LandAmerica Financial</eud:ENTRIES_WORKORGANIZATION>
    <eud:ENTRIES_OTHERPHONE>(714) 551-3743</eud:ENTRIES_OTHERPHONE>
    <eud:ENTRIES_NICKNAME>Diane</eud:ENTRIES_NICKNAME>
    <eud:ENTRIES_OTHEREMAIL rdf:resource="mailto:diane.barnes@landamericafinan cial.com"/>
    <eud:ENTRIES_COUNTRY>US </eud:ENTRIES_COUNTRY>
    <eud:ENTRIES_WORKFAX>(666) 371-9322 </eud:ENTRIES_WORKFAX>
    <eud:ENTRIES_WORKCITY>Quebec</eud:ENTRIES_WORKCITY>
    <eud:ENTRIES_WEB>http://www.landamericafinancial.com/Diane </eud:ENTRIES_WEB>
    <eud:ENTRIES_WORKZIP>70596 </eud:ENTRIES_WORKZIP>
    <eud:ENTRIES_MOBILE>(705) 625-6032 </eud:ENTRIES_MOBILE>
    <eud:ENTRIES_WORKMOBILE>(607) 280-8253 </eud:ENTRIES_WORKMOBILE>
    <eud:ENTRIES_PHONE>(328) 852-8160 </eud:ENTRIES_PHONE>
    <eud:ENTRIES_CITY>Victoria</eud:ENTRIES_CITY>
    <eud:ENTRIES_LASTNAME>Barnes</eud:ENTRIES_LASTNAME>
    <eud:ENTRIES_WORKSTATE>MO</eud:ENTRIES_WORKSTATE>
    <eud:ENTRIES_EMAIL1 rdf:resource="mailto:diane807@msn.com"/>
    <eud:ENTRIES_ZIP>62819-8803</eud:ENTRIES_ZIP>
    <eud:ENTRIES_WORKPHONE>(658) 698-1087 </eud:ENTRIES_WORKPHONE>
    <eud:ENTRIES_WORKCOUNTRY>US </eud:ENTRIES_WORKCOUNTRY>
    <eud:ENTRIES_ADDRESS>313 Jefferson Ave.</eud:ENTRIES_ADDRESS>
    <eud:ENTRIES_FAX>(770) 631-3744 </eud:ENTRIES_FAX>
    <eud:ENTRIES_WORKADDRESS>3277 Washington Road</eud:ENTRIES_WORKADDRESS>
    <eud:ENTRIES_FIRSTNAME>Diane</eud:ENTRIES_FIRSTNAME>
    <rdfs:label>ENTRIES #Diane/Barnes</rdfs:label>
    <eud:ENTRIES_STATE>LA</eud:ENTRIES_STATE>
  </eud:ENTRIES>
</rdf:RDF>

I am trying to get some xslt produce the following

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#">
  <rdf:Description rdf:about="http://localhost:2020/resource/ENTRIES/Diane/Barnes">
    <rdf:type>
      <owl:Class rdf:about="http://localhost:2020/resource/eudora/ENTRIES"/>
    </rdf:type>
    <eud:ENTRIES_WORKWEBADDRESS xmlns:eud="http://localhost:2020/resource/eudora/" >http://www.landamericafinancial.com </eud:ENTRIES_WORKWEBADDRESS>
    <eud:ENTRIES_FULLNAME xmlns:eud="http://localhost:2020/resource/eudora/" >Diane Barnes</eud:ENTRIES_FULLNAME>
    <eud:ENTRIES_WORKORGANIZATION xmlns:eud="http://localhost:2020/resource/eudora/" >LandAmerica Financial</eud:ENTRIES_WORKORGANIZATION>
    <eud:ENTRIES_OTHERPHONE xmlns:eud="http://localhost:2020/resource/eudora/" >(714) 551-3743</eud:ENTRIES_OTHERPHONE>
    <eud:ENTRIES_NICKNAME xmlns:eud="http://localhost:2020/resource/eudora/" >Diane</eud:ENTRIES_NICKNAME>
    <eud:ENTRIES_OTHEREMAIL xmlns:eud="http://localhost:2020/resource/eudora/" rdf:resource="mailto:diane.barnes@landamericafinan cial.com"/>
    <eud:ENTRIES_COUNTRY xmlns:eud="http://localhost:2020/resource/eudora/" >US </eud:ENTRIES_COUNTRY>
    <eud:ENTRIES_WORKFAX xmlns:eud="http://localhost:2020/resource/eudora/" >(666) 371-9322 </eud:ENTRIES_WORKFAX>
    <eud:ENTRIES_WORKCITY xmlns:eud="http://localhost:2020/resource/eudora/" >Quebec</eud:ENTRIES_WORKCITY>
    <eud:ENTRIES_WEB xmlns:eud="http://localhost:2020/resource/eudora/" >http://www.landamericafinancial.com/Diane </eud:ENTRIES_WEB>
    <eud:ENTRIES_WORKZIP xmlns:eud="http://localhost:2020/resource/eudora/" >70596 </eud:ENTRIES_WORKZIP>
    <eud:ENTRIES_MOBILE xmlns:eud="http://localhost:2020/resource/eudora/" >(705) 625-6032 </eud:ENTRIES_MOBILE>
    <eud:ENTRIES_WORKMOBILE xmlns:eud="http://localhost:2020/resource/eudora/" >(607) 280-8253 </eud:ENTRIES_WORKMOBILE>
    <eud:ENTRIES_PHONE xmlns:eud="http://localhost:2020/resource/eudora/" >(328) 852-8160 </eud:ENTRIES_PHONE>
    <eud:ENTRIES_CITY xmlns:eud="http://localhost:2020/resource/eudora/" >Victoria</eud:ENTRIES_CITY>
    <eud:ENTRIES_LASTNAME xmlns:eud="http://localhost:2020/resource/eudora/" >Barnes</eud:ENTRIES_LASTNAME>
    <eud:ENTRIES_WORKSTATE xmlns:eud="http://localhost:2020/resource/eudora/" >MO</eud:ENTRIES_WORKSTATE>
    <eud:ENTRIES_EMAIL1 xmlns:eud="http://localhost:2020/resource/eudora/" rdf:resource="mailto:diane807@msn.com"/>
    <eud:ENTRIES_ZIP xmlns:eud="http://localhost:2020/resource/eudora/" >62819-8803</eud:ENTRIES_ZIP>
    <eud:ENTRIES_WORKPHONE xmlns:eud="http://localhost:2020/resource/eudora/" >(658) 698-1087 </eud:ENTRIES_WORKPHONE>
    <eud:ENTRIES_WORKCOUNTRY xmlns:eud="http://localhost:2020/resource/eudora/" >US </eud:ENTRIES_WORKCOUNTRY>
    <eud:ENTRIES_ADDRESS xmlns:eud="http://localhost:2020/resource/eudora/" >313 Jefferson Ave.</eud:ENTRIES_ADDRESS>
    <eud:ENTRIES_FAX xmlns:eud="http://localhost:2020/resource/eudora/" >(770) 631-3744 </eud:ENTRIES_FAX>
    <eud:ENTRIES_WORKADDRESS xmlns:eud="http://localhost:2020/resource/eudora/" >3277 Washington Road</eud:ENTRIES_WORKADDRESS>
    <eud:ENTRIES_FIRSTNAME xmlns:eud="http://localhost:2020/resource/eudora/" >Diane</eud:ENTRIES_FIRSTNAME>
    <rdfs:label xmlns:eud="http://localhost:2020/resource/eudora/" >ENTRIES #Diane/Barnes</rdfs:label>
    <eud:ENTRIES_STATE xmlns:eud="http://localhost:2020/resource/eudora/" >LA</eud:ENTRIES_STATE>
  </rdf:Description>

You can see in the original xml that the email1 node has a attribute.

I am using the following xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                     xmlns:owl="http://www.w3.org/2002/07/owl#"
                     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

  <xsl:strip-space elements="*"/>
  <xsl:output indent="yes"/>

  <xsl:template match="rdf:RDF">
        <xsl:apply-templates select="*"/>

  </xsl:template>

 <xsl:template match="*[@rdf:about]">
      <rdf:Description rdf:about="{@rdf:about}">

      <rdf:type>

        <owl:Class rdf:about="{namespace-uri(.)}{local-name()}"/>

      </rdf:type>


         <xsl:apply-templates select="node()"/>
    </rdf:Description>

  </xsl:template>


 <xsl:template match="node()">
 <xsl:copy>
    <xsl:apply-templates select="node()"/>
 </xsl:copy>
 </xsl:template>


</xsl:stylesheet>


The problem I am having is that the email1 line does not include the rdf:resource attribute.
I have tried copy-of with select="." but that includes all of the xmlns values given at the top of the xml file.

I have tried a variety of things and sometime I get the dat values without the tags, othertimes I get the tags without the data.
This is the closest I have got.

How do I keep the rdf:resource attribute of the email1 tag

Thanks in advance
Phil ashworth




Reply With Quote
  #2 (permalink)  
Old January 29th, 2007, 12:09 PM
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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The simplest would be to change your identity template to

<xsl:template match="node()">
 <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="node()"/>
 </xsl:copy>
</xsl:template>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old January 29th, 2007, 12:16 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael
I have already tried this and the output I get for a single node is.
    <eud:ENTRIES_WORKWEBADDRESS xmlns:db="http://localhost:2020/resource/" xmlns:omap="file:///C:/d2r-server-0.3.1/outlookmap.ttl#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:emap="file:///C:/d2r-server-0.3.1/eudoramap.ttl#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:out="http://localhost:2020/resource/outlook/" xmlns:eud="http://localhost:2020/resource/eudora/" xmlns:xi="http://www.w3.org/2001/XInclude">http://www.landamericafinancial.com </eud:ENTRIES_WORKWEBADDRESS>

How can I stiop all of these xmlns's getting included.

Cheers

Phil


Reply With Quote
  #4 (permalink)  
Old January 29th, 2007, 12:39 PM
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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

That's a completely unrelated problem.

<xsl:copy> copies an element node together with all its in-scope namespaces.

In 2.0 you can use

<xsl:copy copy-namespaces="no">

In 1.0 you can use

<xsl:element name="{name()}" namespace="{namespace-uri()}">

so long as no namespace prefixes are used in the content (as distinct from the names) of your elements and attributes.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
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
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Accessing data From a node austinf XML 1 June 7th, 2006 02:16 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM



All times are GMT -4. The time now is 07:03 AM.


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