|
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
|
|
|
April 21st, 2008, 12:55 PM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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,
|
April 23rd, 2008, 07:53 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I'm not 100% sure but does this not work:
Code:
<xsl:value-of select="unparsed-entity-uri('phone')" />
/- Sam Judson : Wrox Technical Editor -/
|
April 23rd, 2008, 09:35 AM
|
|
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
April 23rd, 2008, 10:48 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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
|
April 23rd, 2008, 12:59 PM
|
|
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
April 23rd, 2008, 02:14 PM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Thanks...Good idea. I will try.
|
April 28th, 2008, 10:52 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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;
}
}
|
|
|