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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Complex Scenario - loadxml transform

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
US
I have a template which is passed a list of XML files to open and use within the template. It works fine, but now I have a problem being that I need to be able to change the XML file that is originally passed in the ASP. Here is the current code:

Code:
<%@ Language=VBScript %>
<%
Dim objTemplate, objProcessor, strSortField, strGameNumber, objXML, objXSL, strHTML, aSTR, Root, xmlDoc2 
	Set objXML = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
	Set objXSL = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
	Set xmlDoc2 = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
	
		objXSL.async = False
		objXSL.Load Server.MapPath("DVD_All_Temp.xsl")
		Set objTemplate = Server.CreateObject("MSXML2.XSLTemplate.3.0")
		Set objTemplate.stylesheet = objXSL
		Set objProcessor = objTemplate.createProcessor
	
	
	if cstr(Request.QueryString("Key")) = "all" or cstr(Request.QueryString("Key")) = "" then
		objXML.async = False	
		objXML.Load Server.MapPath("DVD_Cats.xml")


		objProcessor.input = objXML
		call objProcessor.addParameter("Key", cstr(Request.QueryString("Key")))	
		objProcessor.Transform
		strHTML = objProcessor.output
		Response.write strHTML		
	else
		xmlDoc2.async = False	
		xmlDoc2.loadXML("<cats TS=""""><cat name=""DVD_Cat_4.xml"" k=""4"" /></cats>")
		Set Root = xmlDoc2.documentElement 
		'response.write(Root.xml)
		
		objProcessor.input = Root.xml
'		call objProcessor.addParameter("Key", cstr(Request.QueryString("Key")))	
'		objProcessor.Transform		
		
		
	end if
%>

As you can see, I have an if condition. If the URL param is not present, or "all", then the it uses a file ("DVD_Cats.xml").

What I want to do, is that if this condition is not met, then I would like to construct an XML fragment:

Code:
<cats TS="">
   <cat name="DVD_Cat_4.xml" k="4" />
</cats>

I have tried the loadXML command, and can print it out to the screen; however, I can't figure out how I can use it to pass it to be used as input for the template, as the objXML instead of using the static file (above).

Please help. Until now, I have had to just re-direct to another template, but I am tired of doing so.
 
After the LoadXml you can work with the XmlDoc2 just as you are with objXml. No difference! Do you get any error messages?

And I think you would get a lot more answers if you would post this in an Asp Forum rather than Xml.

Stephan
 
OK, I have now figured out a what the true problem is.

My internal structure is that I have this ASP page, which determines to either use the static full list, or the dynamically created one. Then it calls the XSLT template, which then, within the called template used the following statement:

Code:
<xsl:for-each select="msxsl:node-set($doc.refs.1)//doc" >
  <xsl:call-template name="DVDGroup" >
    <xsl:with-param name="atDVDFile" select="document(.)"/>
  </xsl:call-template>
</xsl:for-each>


I don't know why it works for one, but not the other. I can print out the "." value, and they appear to be correct. Any ideas why it appears the $atDVDFile param wont let me traverse the movies/@cat? Here is a sample of the actual file it should load:




Code:
<movies TS="" cat="H" DVDCount="149">
  <movie name="Hackers" />
  <movie grp="Harry Potter">
    <mov name="Harry Potter" n="1" 
      subname="Sorcerer's Stone, and the" />
    <mov name="Harry Potter" n="2" 
      subname="Chamber of Secrets, and the" />
    <mov name="Harry Potter" n="3" 
      subname="Prizsoner of Azkaban, and the" />
  </movie>
  <movie name="HellBoy" />
  <movie name="Holes" />
  <movie name="How the Grinch Stole Christmas" />
  <movie name="How to Lose a Guy in 10 Days" />
</movies>




This works fantastic for the full static version, but when I use the dynamic, I get this error:

Code:
msxml3.dll error '800c0006' 

The system cannot locate the object specified. 

/multimedia/movies/index_all.asp, line 24

It errors when I get to this statement:
Code:
<xsl:template name="DVDGroup" >
  <xsl:param name="atDVDFile" select="." />
    <table border="0"
      cellpadding="0"
      cellspacing="0"
      class="mp3z_table">
      <tr class="mp3z_category">
        <td>
          <xsl:value-of select="$atDVDFile//movies/@cat" />
        </td>
      </tr>
    </table>
    <br />
</xsl:template>



 
hmmm not really sure but... you could try msxml:node-set() around that $atDVDFile?

 
I wish it were that simple. If I try your suggestion, I get and error that states it doesn't recognize the msxsml portion of the call.

I am still currious. the document(.) statement in the first XSL template is supposed to grab the entire document? right? When I print "." on the other side, it prints the name. But when I do this:

//movies/@cat

It doesn't print anything.

Maybe it is just passing the root element? Does anyone know why this is.

Sample XML here

initial XSLT here

The XSLT called from the initial, which does NOT display the data when wanted

Someone, please help. Once again, I believe it is a matter of how load and loadxml and the document(.) work together. If I pass the url param of k="all" then it works correctly, displaying all, but when I pass something else, then I would like to construct the initial XML doc dynamically, and then pass it instead of the static file. For some reason, it won't work?
 
I'm not too good with MSXML any more but reading MSDN isnt the document() function call trying to load an external document URL relative to this document?

THIS
article mentions that if document(' ') is called (an empty document uri) then the root is returned:

If this argument is the empty string, document(' '), then the root node of the stylesheet from where the function call was made is returned.

I get the feeling that if you use "document(text())" it might work.... but dont quote me.
 
OK, I believe the problem is indeed the document() call. I have tested it where I can say:

Code:
document('DVD_Cat_S.xml')

This returns what is expected; however if I use:

Code:
document(.)

Does anyone have any idea why it can't find the simpler of the more complex cases?
 
I think i see your problem now

try

document(./@name) or document(@name) something.


Matt

 
This is so frustrating. I can use this in the for loop:

a<xsl:value-of select="./@name" />a

And it will indeed show that I am passing the correct values, i.e. "aDVD_Cat_A.xmla". Now it is failing. According the document() documentation that was found, if the document fails, it either throws an error, or returns the calling node. I have been able to produce both at times. The document also says that common reason for failing are bad XML structure in the reference passed, or that it can't find the document.

Does anyone know why if I put a static value 'DVD_Cat_5_xml' in the document function, it works, but if I put a dynamic one (. or ./@name or now @name), which has been proven to provide the proper value, does not work, as if it can't find the external document?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top