Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a single webpage from multiple xml files

Status
Not open for further replies.

JasonHampson

Technical User
Feb 20, 2003
16
0
0
GB
I want to create a single web page viewable by Internet Explorer from several XML files. I intend to use XSL style sheets to create and format the document from multiple source files. I would like Internet Explorer to compile the page on-the-fly

(e.g. which calls style sheets to format the data contained in the XML file).

I have been looking on the Internet and people have used the document() function to get information from other XML files but I haven’t been able to get it to work. Could anyone give me a practical example of how a single XML file, when opened, will initiate a style sheet that will obtain data from other XML files.

Cheers

Jay
 
How about
Code:
<xsl:template match=&quot;/&quot;>
  <xsl:variable name=&quot;otherdoc&quot; select=&quot;document('otherdoc.xml')&quot; />
  <xsl:apply-templates select=&quot;$otherdoc&quot; />
</xsl:template>

Just a suggestion ...

-Rob
 
hi,
This is better choice

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; <xsl:template match=&quot;/&quot;>
<html>
<head>
<title>Merging of multiple xml Documents using XSLT</title>
</head>

<!--===============Files are stored as variables=====================-->

<xsl:variable name=&quot;doc&quot; select=&quot;document('Sample.xml')&quot;/>
<xsl:variable name=&quot;schea&quot; select=&quot;document('test.xml')&quot;/>
<xsl:variable name=&quot;att&quot; select=&quot;document('

<!--===================Applying those variables======================================-->
<xsl:apply-templates select=&quot;$schea/* &quot;/>
<xsl:apply-templates select=&quot;$doc/* &quot;/>
<xsl:apply-templates select=&quot;$att/* &quot;/>

<body/>
</html>
</xsl:template>
</xsl:stylesheet>
 
I adapted your above example to create:



<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; <xsl:template match=&quot;/&quot;>
<html>
<head>
<title>Merging of multiple xml Documents using XSLT</title>
</head>

<!--===============Files are stored as variables=====================-->
<!--<xsl:for-each select=&quot;/DOCUMENTS/DOCUMENT&quot;>-->
<xsl:variable name=&quot;Doc&quot; select=&quot;document('CSS_Acceleration ACU Control - Acceleration ACU Control().xml')&quot;/>
<xsl:apply-templates select=&quot;$Doc/* &quot;/>
<!--</xsl:for-each>-->



<body/>
</html>
</xsl:template>



<xsl:template match=&quot;OBJECT[TYPE = 'Heading']&quot;>


<H2><A><xsl:attribute name=&quot;name&quot;><xsl:value-of select=&quot;HEADING&quot;/><xsl:value-of select=&quot;ID&quot;/></xsl:attribute><xsl:value-of select=&quot;HEADING&quot;/></A></H2>


<P><xsl:value-of select=&quot;TEXT&quot;/></P>

<xsl:apply-templates/>

</xsl:template>


<xsl:template match=&quot;OBJECT[TYPE = 'Requirement']&quot;>


<A name=&quot;A link Value&quot;><H3>Requirement: <xsl:value-of select=&quot;ID&quot;/></H3></A>

<H3><A><xsl:attribute name=&quot;name&quot;><xsl:value-of select=&quot;HEADING&quot;/><xsl:value-of select=&quot;ID&quot;/></xsl:attribute>Requirement: <xsl:value-of select=&quot;ID&quot;/></A></H3>

<P>Text:<xsl:value-of select=&quot;TEXT&quot;/></P>

<xsl:apply-templates/>

</xsl:template>


<xsl:template match=&quot;OBJECT[TYPE = 'Informative Text']&quot;>


<P>Text</P>

<I><xsl:value-of select=&quot;TEXT&quot;/></I>


<xsl:apply-templates/>

</xsl:template>



<xsl:template match=&quot;LINKS&quot;>
<xsl:apply-templates/>
</xsl:template>



<xsl:template match=&quot;OUTGOING_LINKS[LINK]&quot;>

<P>Outgoing Links</P>
<xsl:for-each select=&quot;LINK&quot;>

<LI><xsl:value-of select=&quot;MODULE&quot;/> - <xsl:value-of select=&quot;HEADING&quot;/>(<xsl:value-of select=&quot;ID&quot;/>) Type: <xsl:value-of select=&quot;TYPE&quot;/></LI>
</xsl:for-each>

</xsl:template>




<xsl:template match=&quot;INCOMING_LINKS[LINK]&quot;>

<P>Incoming Links</P>
<xsl:for-each select=&quot;LINK&quot;>

<LI><xsl:value-of select=&quot;MODULE&quot;/> - <xsl:value-of select=&quot;HEADING&quot;/>(<xsl:value-of select=&quot;ID&quot;/>) Type: <xsl:value-of select=&quot;TYPE&quot;/></LI>
</xsl:for-each>

</xsl:template>



<xsl:template match=&quot;SUB_HEADING&quot;>

<H3><A><xsl:attribute name=&quot;href&quot;><xsl:value-of select=&quot;MODULE&quot;/> - <xsl:value-of select=&quot;HEADING&quot;/>(<xsl:value-of select=&quot;ID&quot;/>).xml</xsl:attribute><xsl:value-of select=&quot;HEADING&quot;/></A></H3>

<!--===============<xsl:element name=&quot;A&quot; use-attribute-sets=&quot;LinkSet&quot;/>-->

</xsl:template>



</xsl:stylesheet>




Which produced:


;
Requirement:
Requirement:
Text:
Text
Outgoing Links
· - () Type:
Incoming Links
· - () Type:
- ().xml


in internet explorer.

Can you tell me what I’ve done wrong. Ideally the for loop I’ve commented out would loop through a list of document names in the file which calls the style sheet.
 
hi Jason,

The possible suggestions are,

1. Misuse of Element or Attribute. You have used LINK in the template and in the xsl:for-each loop, whether LINK is an element or attribute(if it is an attribute use @LINK).

2. Incorrect XPath. Instead of <xsl:template match=&quot;INCOMING_LINKS&quot;>, you code as <xsl:template match=&quot;//INCOMING_LINKS> for better results.

3. Internet Explorer version problem. If you are using Internet explorer IE 5.0 then, the namespace xsl=&quot; in the stylesheet) will not support. if it is IE 6.0, then the errors are in the stylesheet only.

I have given the above suggestions for fixing of errors. I hope this will solve your errors. Finally, these suggestions fail to give the output, send the xml file(if it is not confidential) to my email id raman_learn@yahoo.co.in as an attachement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top