Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 21st, 2008, 12:55 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default list unparsed-entity-uri()

Hi,

Using Saxon 9.002 and XSLT 2.0, how can I get the value of the an unparsed-entity-uri() with out knowing the name for the entities in the below example?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE DRIVERSLICENSE SYSTEM "driverlicense.dtd" [
    <!ENTITY phone SYSTEM "phone.ent">
    <!ENTITY % commonEnties SYSTEM 'c:/temp/common.ent'> 
    %commonEnties;
]>
Thanks,
 
Old April 23rd, 2008, 07:53 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I'm not 100% sure but does this not work:
Code:
<xsl:value-of select="unparsed-entity-uri('phone')" />
/- Sam Judson : Wrox Technical Editor -/
 
Old April 23rd, 2008, 09:35 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

Support for unparsed entities and notations in the XDM data model is very limited (not many people seem to use them). In particular, you can't find out what entities have been declared, you can only get the system ID and public ID of an entity whose name you already know.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 23rd, 2008, 10:48 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thanks,

"you can only get the system ID and public ID of an entity whose name you already know." - this is my dilemma.

The XML files uses numerious entity references, but these references are burried in other entity files, which makes for inventoring these files a mess. I need GPS to navigate these files! The best way to describe it is "like a daisy chain". A poor design, which makes reading them horrible.

Maybe you may have some suggestions to do the following:

I wrote an XSLT file (called from a java swing app) that will to output all the base-uri's to temp.xml file. I then read this XML file (using Saxon xpath) and zip those files. This works great except if the entity is not directly called. I am up for any "out-of-the-box" suggestions (if any)

Thanks for the help.

Regards

 
Old April 23rd, 2008, 12:59 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: 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

Basically, XSLT doesn't have access to this information. I would write a SAX application in Java to collect notifications of the entity declarations from the XML parser, then write the list of entity names to an XML document, then process this XML document using XSLT.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 23rd, 2008, 02:14 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thanks...Good idea. I will try.


 
Old April 28th, 2008, 10:52 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi,

Solved! If any one is interested:


Code:
 try {
                // Create an XML parser
                DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                // Install the entity resolver
                builder.setEntityResolver(new MyResolver());
                // Parse the XML file
                org.w3c.dom.Document doc = builder.parse(new File(myXML.xml));

            } catch (SAXException e) {
            // A parsing error occurred; the xml input is not valid
            } catch (ParserConfigurationException e) {
            } catch (IOException e) {
            }


Entity Resolver:

Code:
 public class MyResolver implements EntityResolver {

        public InputSource resolveEntity(String publicId, String systemId) throws FileNotFoundException {
            try {

                URI uri = new URI(systemId);

                System.out.println(systemId);                    

            } catch (URISyntaxException e) {

            }

            return null;
        }
    }






Similar Threads
Thread Thread Starter Forum Replies Last Post
unparsed-entity-uri() changes files extension scopley XSLT 6 November 28th, 2007 10:45 AM
chapter 2, error uri cannot be resolved in either boylevel BOOK: Beginning JavaServer Pages 2 November 21st, 2007 12:54 PM
How do I get only the filename of the reffered URI shekhar_249 General .NET 1 August 25th, 2006 06:40 AM
Difference between Entity and Entity type arshad mahmood C++ Programming 0 May 8th, 2004 12:34 AM
Referrer and Uri druid2112 General .NET 1 April 20th, 2004 12:54 PM





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