Jump to content

dooberry

Members
  • Posts

    133
  • Joined

  • Last visited

Everything posted by dooberry

  1. Hmm, your code has given me and idea - If I use a template that matches the node in "memory" and then use a template which matches the external document node, I can use the <xsl:when> element to apply the appropriate template as required.When I've sorted it I'll post the code.
  2. Yeah, that looks like it might do the trick.As far as your other comment goes, you're right - I'm weird and my communication skills aren't brilliant! :)Thanks for your help.Doobs.
  3. Gosh Darn it!!!I've hit a barrier because I'm traversing documents.I'm creating nodes as I go to minimise the amount of memory used by the client when holding the document (which is the real part of the problem). What I need to do is look at another document which holds default values for a set of nodes, but substitute the values with those contained by the document in memory if they exists - here's an illustration of what I would do if both documents were saved: <xsl:for-each select="document('externalitems.xml')//externalitem" ><xsl:variable name="id" select="id" /><xsl:if test="exists(document('newdata.xml')//information/items[id=$id])" > <xsl:value-of select="document('newdata.xml')//information/items[id=$id]/data" ></xsl:if><xsl:value-of select="itemdata" /></xsl:for-each> What I would like to do is use <xsl:if> to replace the <itemdata> values with the values held by my document in memory (it does not exist on the client disk at this point!). Is this even possible without saving the document that I need to check?
  4. dooberry

    XML - DTD

    Err, just re-checking your initial post, you could make solution a child element of row: <Row><id>1</id><Problem> <Letter>M</Letter></Problem<Solution> <Letter>M</Letter></Solution></Row>... Then have 2 XSL sheets, one which does this: <table><xsl:for-each select="Row"><td> <xsl:value-of select="Problem/Letter" /></td></xsl:for-each></table> And another which does this: <table><xsl:for-each select="Row"><td> <xsl:value-of select="Solution/Letter" /></td></xsl:for-each></table> that's what I would do because I have absolutely no idea about DTD.There may be other people out there who can help with this a bit more and give you what you need to put this into DTD, but hopefully what I've given you here is a little insight as to how it could be done.Sorry if this was no help at all!! Dooberry.
  5. If you're using script then try the selectSingleNode method: set xmldoc = CreateObject("Microsoft.XMLDOM")response.write(xmldoc.documentelement.selectsinglenode("Banner[@display='true']").text) This allows you to tie your code in more closely with XSL where you would use : <xsl:value-of select="Banner[@display='true']" /> I'd say this as well, a little XSL can replace a lot of script when it comes to displaying xml data (and you can even build script into XSL if you really need to!). Hope this helps.Dooberry
  6. I've just stumbled across this one which means that you might be able to return the favourSomething like: <xsl:variable name="Cmpny" select="Company" /><company><xsl:value-of select="$Cmpny"/><xsl:for-each select="account[company=$cmpny]"><account><xsl:value-of select="account" /></account></xsl:for-each></company> There'll probably be tweaks to make to this code - I don't think it'll give you unique company names for instance (something you might be able to get round with a primary key in your database, or waiting for XML version 2!), but if my brain is working properly then this should help at least.Looks like you've been waiting a while too! :)Dooberry.
  7. Wow, looks like I've still got a lot to learn!!
  8. Hmm,This is a funny one. I can see the merits of you xml structure, but I would suggest that you don't use this.I think you need to re-structure your xml so that it reads: <statistics><statistic> <year>1999</year> <population>88,100,000</population> <unemployment>3.14</unemployment></statistic>...</statistics> Then use a style sheet which reads these three tags and puts them into a table: <xsl:template match="statistic" ><table><tr><td> <p><strong>Year:</strong></p></td><td><xsl:value-of select="year" /></td></tr><tr><td> <p><strong>U.S. Population</strong></p></td><td><xsl:value-of select="population" /></td></tr><tr><td> <p><strong>Unemployment Percentage</strong></p></td><td><xsl:value-of select="unemployment" /></td></tr></table> That's just one way to present the data in a table using XSL. For your purposes where you want to use RTF, you can just substitute the table information for the equivalent RTF text: \trowd \intbl Year: <xsl:value-of select="year" /> \cell \intbl U.S. Population: <xsl:value-of select ="population" /> \cell \intbl Unemployment Percentage: <xsl:value-of select="unemployment" /> \cell \row The reason I would do this is that I say XML is supposed to separate data from functionality. XML should only contain data - XSL, CSS or your custom application should act on the data to show it or change it or behave in a particular way - the whole point is that XML is intended to be "independent" of the system that wants to use it.I find if I treat xml in this way, it becomes a easier to maintain because I can modify behaviour without worrying about the data.It would be interesting to see what other people think about this though.:)Dooberry.
  9. Yay!! :)This worked. Not only did it work, but it's also allowed me to halve the amount of code that I need to write because I don't have to save the document until all the data has been submitted.Reworking the code was fun to and for a client side application this is probably a better way of doing the job.Woohoo!
  10. Try this <xsl:when test="boolean($thisSong/[artist=concat('Artist',string($artistCount)))]" /> I've made a best guess based on some code I've used to create an id attribute when I load information into a textbox control.Let us know if it doesn't work.Dooberry
  11. Yeah, I think thats what I mean.I was going to use a global script variable to hold the XML document in memory, then I was just going to use the transformNode() method combined with an XSL file name to transform the data.Here's some rough code to give the idea: <script language="javascript" >var rootdocvar basenoderootdoc = new ActiveXObject("Microsoft.XMLDOM")rootdoc.async = falsebasenode = rootdoc.createElement("mynewelement")rootdoc.documentElement.appendChild(basenode)function displaypage(xslparam){ var xsldoc xsldoc = new ActiveXObject("Microsoft.XMLDOM") xsldoc.async = "false" xsldoc.load(xslparam) document.write rootdoc.transformNode(xsldoc)}</script> I assumed that this would hold the data of the XML document until the document is saved and then it could be re-initialised once the data is stored.Dooberry
  12. OK, I'm pushing back my boundaries now.Up to this point I have worked with an existing xml file and a bunch of xsl files which all transform it in different ways.I was wondering (and I'm sure that someone must have done it!) - I can create an object in memory that is a blank XML document a new instance of the XMLDOM object.If I want to change it, I can change it - no problem because I just use the object methods.Can I still use transformnode to change the presentation of it?Do I need to add processing instructions to it (including the xml version instruction)?If anyone can offer advice I'd appreciate it.Hey, while I'm taking this approach to questioning - I know that we have the wonderful W3 schools tutorials but - Has anyone thought of putting an FAQ section on the forums because I keep seeing the same questions being asked by different members and it seems a shame to have to trawl through masses of topics to find the answer to what may be a simple question that isn't covered by the tutorials.Doo (Halle) Berry - yeah you would!
  13. dooberry

    XML - DTD

    You might want to look at the posts about the Sudoku puzzle that is being worked on (search on Little Goat's posts). This should allow you to plan the crossword better because you will be able to plot a grid using the SML:Grid namespace.
  14. dooberry

    XMLDOM question

    I fixed it.According to the w3 tutorial the child node should be the name of the node that needs to be removed - I assumed that this meant the string which represents the name.In actual fact, the removeChild() method needs to have the node object passed to it.in this case: rootel = xmldoc.documentElement.selectSingleNode("Products")if (rootel.childNodes.length){removenode = rootel.selectSingleNode("product[id='product" + rootel.childNodes.length + "']")rootel.removeChild(removenode)} I could have reduced the number of steps in the code by writing: if (rootel.childNodes.length){rootel.removeChild(rootel.selectSingleNode("product[id='product" + rootel.childNodes.length + "']"))} but that makes the code less readable!
  15. dooberry

    XMLDOM question

    Guys,I'm having some trouble with the removeChild() method and I was wondering if I could get any help.I have some xml as follows: <products><product> <id>product1</id> <description>Product type 1</description> <price>100</price></product><product> <id>product2</id> <description>Product type 2</description> <price>100</price></product><product> <id>product3</id> <description>Product type 3</description> <price>100</price></product></products> When I try to use the removeChild method (as follows) I get an error: xmldoc=new ActiveXObject("Microsoft.XMLDOM")xmldoc.async="false"xmldoc.load("products.xml")node = xmldoc.documentElement.selectSingleNode("Products")nodename = "product[id='product" + node.childNodes.length +"']"node.removeChild(nodename) Can someone tell me why the removeChild() method is generating an error?I think it has something to do with the way I've idenitified the products, but I can't see what's wrong with the code.thanks in advance.Dooberry
  16. Guys,I'm at the end stage of my project and I'm going to use my project to submit data from an xml file into a database.For example if I have this in my xml data: <object><dataitem> <id>idvalue</id> <value>val1</value> <value>val2</value> <value>val3</value> <value>val4</value></dataitem></object> I want XSL to read the values of the XML document and submit them to a db using ADO.Is there a way of using XSL to post the values of the document to the database or do I have to use script to do it?I was thinking that I might be able to use the xsl:template element to execute the script, but I can see problems with this already (the script won't understand <xsl:value-of> for example!!).If I have to write a page which entirely uses code then I'm ok with it, but I'd prefer to try and be clever with it (HA! wouldn't we all ).Any donations would be gratefully received.
  17. Wow, I guess I opened a can of worms there!!
  18. I agree with Boen. I think frames are going to be your best bet for this, but you will find that you need to separate the XSL and the XML for the buttons into other sources - if you don't, you could have the buttons appearing on your screen twice, once when you load them into the first frame and again when you load the data. That would only confuse the person reading the page.try something like : <frameset rows="10%,90%"><frame id="pheader" src="mybuttons.xml" /><frame id="pbody" src="mydata.xml" /></frameset> If you want the buttons to change the frame content in the body of the form, then you can add script to the buttons xml file which changes the src property of the frame called "pbody".Personally, I would suggest that this is more than you need to do (although it does look nice!) and you could even just put anchors in the header frame which link to the page you need to show in the body of the document. If you do go down the button route then put some code in like: <script language="Javascript">function loadnewpage(sourcedoc){window.frameElement.parentElement.document.frames['pbody'].src = sourcedoc}</script> Each button can then submit it's own url for sourcedoc using the onclick event.Have fun - Dooberry
  19. I've done this!!The way I did it was to set up a procedure in the main page which used XMLDOM to transform a page based on 2 variables - one was the xml file name as a string, the second was the xsl file name as a string. Sub transformfiles(xmlsource, xslsource)Dim xmldoc, xsldocSet xmldoc = CreateObject("Microsoft.XMLDOM")Set xsldoc = CreateObject("Microsoft.XMLDOM")xmldoc.load xmlsourcexsldoc.load xslsourcexmldoc.async = falsexsldoc.async = falsedocument.getelementbyid("outputsection").innerhtml = xmldoc.transformnode(xsldoc)End Sub I then created an element which had an onclick event defined to submit 2 parameters to this procedure <input type="button" value="view transform 1" onclick="transformfiles('xmlsource.xml','xslsource.xsl')" /> One of the key things here is that you will want to define an element like a table cell or a div element where the output is supposed to go.This will stop you from overwriting the main document with the transform and losing the buttons that work the transforms!!Enjoy - Dooberry
  20. dooberry

    XSLT

    Hmm, sounds like a funny one.Like Boen says - if you want to generate multiple copies, you need to decide whether the user or the application controls how many copies are generated first. Once you've decided the way to control the number of copies try something like : <script language="VBscript" >Sub gen_copies(no_of_copies, source_doc, transform_doc, output_doc)Dim s_doc, t_doc, o_docSet s_doc = CreateObject("Microsoft.XMLDOM")s_doc.async = "false"s_doc.open source_docSet t_doc = CreateObject("Microsoft.XMLDOM")t_doc.async = "false"t_doc.open transform_docSet o_doc = CreateObject("Microsoft.XMLDOM")o_doc.async = "false"o_doc.open output_doc For counter = 1 to no_of_copieso_doc.write s_doc.transformnode(t_doc)Next counterEnd sub</script> This is very rough code, but you can then submit your data (xml file)using source_doc, your transform (xsl file) is in transform_doc and your output file is in output_doc.You would probably have to change a lot of the code relating to o_doc to suit the format of your output, but this should give you an idea of how you could do it.Have fun.Dooberry
  21. Hi,I'm probably butting in a bit here, but you could change the function call to include parameters which take the control id, and add an attribute to the control - like an section number: <input type="checkbox" id="check1" divsection="mydiv1" onclick="check(this.id, this.divsection)" /> Then change your function to: function check(checkboxid, divid){if (document.getElementById(checkboxid).checked)document.getElementById(divid).style.display="block";else {document.getElementById(divid).style.display="none"};} This also means that you don't have to change the number in the loop if you add new sections to the page.Sorry if that makes me seem like a smartarse, just offering some help. :)Dooberry.
  22. Yeah,I forgot to mention that you will need an instance of the TextStreamObject object as well, but the reference for this won't be far away from the link I gave you, sorry about that.In the words of Joey Tribiani's agent Have fun.Dooberry.
  23. VBScript will support something called (eurrgh!!) the "Scripting.FilesystemObject".If you create a new instance in vbscript of the above object (provided you are running IE to do the work), you will be able to read from the file using delimiters (e.g. a space character) to separate data items.You can then use a second instance to output to a new file and add in your xml tags.The most horrible thing about this is that you have to know when the data items start and end and what each data element contains.try looking at this link and see if it helps:msdn FileSystemObject referenceIf there is any way at all that you can change the output of the data to have better delimiters and write one "record" per line of data then I would suggest you do it - this will save you a lot of heartache when you convert the data.Hope this helps, give me some feedback if it doesn't. .Dooberry
  24. dooberry

    XML to JSP

    try this in an XSL file: <?xml version="1.0" ?><xml-stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><html><xsl:for-each select="Unit"><xsl:value-of select="QuestionNo" /><b><xsl-value-of select="Subject" /></b>:<xsl:value-of select="Question" /><xsl:for-each select="Answer[@correct!='Y']"><input type="radio"><xsl:attribute name="name"> <xsl:value-of select="'Answer'" /> <xsl:value-of select="QuestionNo" /></xsl:attribute><xsl:attribute name="value"> <xsl:value-of select="Answer" /></xsl:attribute></input><br /></xsl:for-each><br /></xsl:for-each></html></xsl:stylesheet> If you save this in a file on the server with a ".xsl" extension then you can link to it using the following link at the top of your xml file: <? xml-stylesheet type="text/xsl" href="newxslfilename.xsl" ?> This is only a presentation layout, but you can change the code so that you have a <script> section under the html tag to evaluate the questions. The XSL tutorials on w3schools.com will help you a lot with this, and let me know if there is a problem with the @correct bit of this code.Hope this helps :)Dooberry
  25. dooberry

    Save XML Data

    This will be a permission setting in your IIS.One of the other guys will be able to offer more help on this because I'm not particularly server oriented (yet).I know this because I had a similar problem with trying to do this on a client application using XML/XSL and the way I got round it was to create an "hta" file for the main page which gave me ownership of the file system through HTTP.What you need to do (I think!! don't take this as gospel) is create a folder that the file gets saved into and give the page read/write access to it. I think this will sort it, but I'm sure someone else will be able to give you more details.Hope this helps,Dooberry.
×
×
  • Create New...