Skip to content

XML / XSL

Discussions on XML and related technologies

This category can be followed from the open social web via the handle xml-xsl@forum.codeproject.com

2.6k Topics 6.8k Posts
  • sorting

    xml algorithms question
    4
    0 Votes
    4 Posts
    14 Views
    L
    Hi, try to put this code: <xsl:sort order="ascending" data-type="text" select="//records/*[name() = $OrderField]"/> Where the parameter $OrderField contains the name of the field to order. Pau
  • XML for persisted data

    database xml c++ html com
    7
    0 Votes
    7 Posts
    28 Views
    E
    The fastest way to extract data from an XML document is to use SAX (Simple API for XML)[^]. All major vendors provide an implemetaion, but it is not a standardized API (a standards body does not control the API) - it is a de fecto standard. SAX uses a streaming model where the XML parser notifies your applicaiton whenever it reads a part of the document and provides the details to you in plain text. There's a good article, part of which describes the SAX programming model at the 'other' site[^]. SAX scales well, but if you're still concerned about performance then you can just read the XML directly usinng file I/O and parse it yourself - that's as efficient as it gets but is difficult to maintain. Jeremy Pullicino wrote: dynamically creating a schema with the fields I will want No need to do this - see my other post about getting data from an XML document. That post uses the DOM, which may end up being too slow for your needs. Again, you can use SAX bu then extracting the relevant data is left an an excercise for you or you can od the do-it-yourself route and again have to deal with that issue but with the benefit of muh better performance. Erik Westermann Author, Learn XML In A Weekend (Fall 2002)
  • passing a variable to xsl

    xml help tutorial question
    2
    0 Votes
    2 Posts
    9 Views
    E
    You can accomplish this, if you're doing this through a browser, with a little bit of processing either in the browser or on the server. In either case, the processing you do is the same. The short story is that you use an XPath expression to extract the value of the node(s) you want to display. Here are the details: I'm going to give you details from part of an example from my soon to be available book not for name recognition, but simply because it is a good example that demonstrates the technique. Assume that you have a site that publishes book reviews - the details of each book (title, author, etc) along with book reviews reside an an XML file that has a relative simple structure. When users hit the site, they receive a page that lists all books and provides a link to the review. The page, in one part of the sample, actually not an HTML page but is an XML file that's transformed on the client using XSL (so the URL users see in the address bar ends in a file name having an XML extension). This, so far, is the first bit of processing you need to do - transform the XML document (in your case the document that contains information about the directory) into a presentable format. The next bit of processing occurs when the user clicks on a record (or book review in this example) to get the details. I made this part of the process easier for myself back in the previous step: I generated links that provide the information I need in this step to extract the information the user wants. In the sample, I generate links that point to an HTML page along with some information on the querystring, to the link I generate looks something like this: <a href="displayReview.htm?Book Title">Book Title</a> So that when the user clicks the link, displayReview.htm can extract the review from the XML file. displayReview.htm contains a little bit of JavaScript that does the following: Extracts the text passed in on the querystring. Creates an instance of the XML DOM. Loads the book reviews document into the DOM. Creates another instance of the DOM. Loads an XSL file into the second DOM. Builds an XPath expression that includes the book's title. Uses the selectSingleNode method to execute the XPath query. Uses the transformNode method to transform the resulting node into some presentable format for the end user. Stuffs the result into the content of the HTML document. It looks rather involved here, but it is straight-forward once you see it in actio
  • CDATA in element attributes?

    tutorial question
    2
    0 Votes
    2 Posts
    11 Views
    P
    John Morales wrote: just encoding the quotes with " works, but i am going to have possibly thousands of entries, i would rather have some way, like the CDATA thing, to tell the parser to ignore the data altogether I may be wrong but the answer is no. If you think about it having quotes like that in the attribute value breaks the whole parsing of the element. I would recommend you move that attribute to an element e.g.: <setting name="CommandLine">notepad.exe "C:\Documents and Settings\moralja\My Documents\text\text.txt"</setting> It actually makes more sense that way too. And if you think that will be a pain with thousands of entries, you could always write a simple XSL file which does it for you in a couple of minutes :) regards, Paul Watson Bluegrass Cape Town, South Africa Simon Walton wrote: "You come across a lot of people who call themselves realists, when they are actually pessimists attempting to look intelligent."
  • Group problem

    question html xml help
    2
    0 Votes
    2 Posts
    6 Views
    R
    One way is to create an XSL and then transform the XML. This can be done by creating two DOM Documents. Load the XML in one and the XSL in one. call TranformNode for the XML by passing the XSL. The XSL could look something like: I like this approoach because if you wish to chnage the format of your data later on all you have to do is change the XSL and your code remains the same.
  • Group problem

    question html xml help
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • XSLT grouping

    xml help question
    2
    0 Votes
    2 Posts
    9 Views
    Z
    I just pasted in a snippet from a similar problem solution. The requirement here was to sort items before gouping them between DIV tags. It may shed some light on the grouping you need. XML: <?xml version="1.0"?> <list> <item at="d">d</item> <item at="e">e</item> <item at="i">i</item> <item at="k">k</item> <item at="l">l</item> <item at="a">a</item> <item at="b">b</item> <item at="c">c</item> <item at="j">j</item> <item at="f">f</item> <item at="g">g</item> <item at="h">h</item> <item at="a">a</item> <item at="b">b</item> <item at="c">c</item> <item at="f">f</item> </list> XSL: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:param name="group">5</xsl:param> <!-- grouping size--> <xsl:variable name="items" select="count(//item)"/> <!-- total number of items--> <xsl:template match="list"> <HTML> <BODY> <xsl:apply-templates select="item"> <xsl:sort select="@at" order="ascending"/> </xsl:apply-templates> </BODY> </HTML> </xsl:template> <xsl:template match="item"> xsl:choose <xsl:when test="position() mod $group =1"> <!-- Begin new group with gn = group # --> <xsl:variable name="gn" select="concat('g', (position() + 4) div 5)"/> <!-- DIV id="g#" --> <xsl:text disable-output-escaping="yes"><DIV id="</xsl:text> <xsl:value-of select="$gn"/><xsl:text disable-output-escaping="yes">"></xsl:text> <p><xsl:value-of select="position()"/> xsl:apply-templates/</p> </xsl:when> <xsl:when test="position() mod $group =0"> <!-- End group --> <p><xsl:value-of select="position()"/> xsl:apply-templates/</p> <!-- /DIV --> <xsl:text disable-output-escaping="yes"></DIV></xsl:text><hr /> </xsl:when> <xsl:when test="not(position() mod $group =0) and position() = $items"> <!-- last item in sorted list--> <p><xsl:value-of select="position()"/> xsl:apply-templates/</p> <!-- /DIV --> <xsl:text disable-output-escaping="yes"></DIV>&
  • Attribute value choking parser?

    xml question html help announcement
    3
    0 Votes
    3 Posts
    9 Views
    Z
    You have a single & character in your xml. Character & cannot be used in text as it is used in markup (the same applies to < character). Replace each occurence of a single character '&' by a sequence of 5 chars &_a_m_p_;. I can't write them here together for the browser would render them to a single &. Just get rid of '_' from the presented sequence. HTH, Zdenek "It's never too late to have a happy childhood." [Tom Robbins]
  • Problem with 'contains' function

    tools help question
    2
    0 Votes
    2 Posts
    11 Views
    M
    I believe it is the context you have shown. Yes contains is valid in MSXML3. If you insist in finding evil in me you will find it, whether it is there or not.
  • XPath query

    xml database help question learning
    4
    0 Votes
    4 Posts
    10 Views
    P
    correct way is item[not(@name)] "When the only tool you have is a hammer, a sore thumb you will have."
  • What wrong with this clause??

    xml question
    4
    0 Votes
    4 Posts
    11 Views
    R
    in line: strVolume="d:\Shared Volume"; you need to have strVolume="d:\\Shared Volume"; This will not show up as an error when u compile but as a warning about some escape characters. Always check warnings. Your code should not only be error free but also warning free. This could be another reason why your code did not work as your code will resolve to D:Share Volume while you are matching d:\shared......
  • Schema: exclude element from occuring within itself?

    xml question database
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • XSL Transform Textarea Problem w/IE6?

    xml help html question announcement
    3
    0 Votes
    3 Posts
    13 Views
    P
    Shouldnt you be using xsl:element to do this? xsl:element Don't have time to test it but I assume something like this: <xsl:element name="textarea"> <xsl:attribute name="FIELD_TYPE">s</xsl:attribute> <xsl:attribute name="DATA_TYPE">T</xsl:attribute> </xsl:element> regards, Paul Watson Bluegrass Cape Town, South Africa
  • Embedded html

    xml html database hardware business
    2
    0 Votes
    2 Posts
    11 Views
    L
    Just in case anyone runs into this problem, here's the solution: use the tag disable-output-escaping="yes" in your value of.
  • exslt set:distinct template order

    xml tutorial question
    1
    0 Votes
    1 Posts
    4 Views
    No one has replied
  • XML Schema for Office Web Component ver 9 and 10?

    xml database question
    1
    0 Votes
    1 Posts
    5 Views
    No one has replied
  • VARIANT to XML?

    xml tutorial question
    2
    0 Votes
    2 Posts
    11 Views
    R
    Could you be a little more explicit. For example do you have a VARIANT holding a string like blah and you wish to put this into an XML document? Or do you have a variant with some data not known and you wish to generate an XML out of it s contents. Well then what should your XML look like? Under what element would you want your VARIANT data to go? Either way you could look into XMLDOMDocument40 LoadXML function. Hope this helps.
  • Loadxmlerror

    json
    5
    0 Votes
    5 Posts
    21 Views
    C
    I do it by hand X|. But I'm writing on a tool for highlighting to HTML code wich I will publish as an article ;). Guess what I can already render XML to HTML! (no XSLT, cause it reads also comments, PIs etc.) All ya need is VBS and MSXML 3. But I still need a few weeks :((.
  • Rendering XML using JSP

    question java sysadmin xml
    3
    0 Votes
    3 Posts
    10 Views
    L
    just use XSL :) - Roman -
  • Web Services Implementation Guide

    wcf xml tutorial com design
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied