Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

JAXP - Fusing XSLT transformation results into a single XML file

Thread view: 
Blue Gecko - 02 Oct 2005 11:22 GMT
Hi all

I should fuse into an XML file the results dynamically generated by XSLT
transformations from some source files (attachment [2]).
The issue is that, obviously, each XSLT transformation generates its own
processing instructons (PIs, for example <?xml ...?>), so I end up (as
you can see in attachment [1]) with a sintactically-broken XML file.
Could you suggest me the most elegant way to resolve such a challenge?

Many thanks

[1] Resulting XML file:
<?xml version='1.0' encoding='iso-8859-1'?>
<siteMap>
 <node href="index.page.teg">
  <!-- This is the insertion point of the XSLT result from the
index.page.teg file -->
  <?xml version="1.0" encoding="iso-8859-1"?>
  <info/>
  <node href="about/index.page.teg">
  <!-- This is the insertion point of the XSLT result from the
about/index.page.teg file -->
   <?xml version="1.0" encoding="iso-8859-1"?>
   <info/>
  </node>
 </node>
</siteMap>

[2] Code recursively generating the node hierarchy:
/*
 Note:
  PrintWriter siteMapWriter is the writing stream of the resulting XML
file (see [1]).
*/
private void buildNodeList(
  NodeList siteNodeList
  )
{
  for(
    int index = 0;
    index < siteNodeList.getLength();
    index++
    )
  {
    Node siteNode = siteNodeList.item(index);
    String pageHref =
siteNode.getAttributes().getNamedItem("href").getNodeValue();

    // Print the map node start!
    siteMapWriter.print("<node href=\"" + pageHref + "\">");

    File pageFile = new File(basePath + pageHref);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);

    try
    {
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(pageFile);
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(this.siteMapWriter);
        pageInfoExtractor.transform(source, result);
    }
    //<snip content="catches"/>

    // Print the map subnodes!
    buildNodeList(
      ((Element)siteNode).getElementsByTagName("node")
      );

    // Print the map node end!
    siteMapWriter.print("</node>");
  }
}
Blue Gecko - 03 Oct 2005 10:39 GMT
> Hi all
>
[quoted text clipped - 4 lines]
> you can see in attachment [1]) with a sintactically-broken XML file.
> Could you suggest me the most elegant way to resolve such a challenge?

Found the trick: a smart guy suggested me to use the
omit-xml-declaration attribute of xsl:output element from the XSLT spec.

> [1] Resulting XML file:
> <?xml version='1.0' encoding='iso-8859-1'?>
[quoted text clipped - 60 lines]
>   }
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.