|
If you are using DOM then try the following. Based on the user's selections create an XSL with the appropriate sort and then apply it to your XML using the DOMDoc object.
|
|
|
|
|
I am using DOM, but i am not very familiar with that. Do you have any example code which might help me ?
da sonu
|
|
|
|
|
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
|
|
|
|
|
hola,
i have this xml recordset which looks like this
<DataSet>
<User>
<ID>JoeG</ID>
<FNAME>Joli</FNAME>
<LNAME>Gantz</LNAME>
<SSN>400-00-0000<SSN
</User>
<User>
<ID>Joe4</ID>
<FNAME>Joseph</FNAME>
<LNAME>Gour</LNAME>
<SSN>500-00-0000<SSN
</User>
<User>
<ID>Joe4</ID>
<FNAME>Joseph</FNAME>
<LNAME>Gour</LNAME>
<SSN>500-00-0000<SSN
</User>
</DataSet>
Basically I am trying to find a way to transform this xml into something that will have two or however many users in a page element so the output would be something like this.
<DataSet>
<page>
<User>
<ID>JoeG</ID>
<FNAME>Joli</FNAME>
<LNAME>Gantz</LNAME>
<SSN>400-00-0000<SSN
</User>
<User>
<ID>Joe4</ID>
<FNAME>Joseph</FNAME>
<LNAME>Gour</LNAME>
<SSN>500-00-0000<SSN
</User>
</page>
<page>
<User>
<ID>Joe4</ID>
<FNAME>Joseph</FNAME>
<LNAME>Gour</LNAME>
<SSN>500-00-0000<SSN
</User>
<User>
<ID>Joe90</ID>
<FNAME>Joseph90</FNAME>
<LNAME>Ninety</LNAME>
<SSN>500-00-0000<SSN
</User>
<page>
</DataSet>
any one have any ideas as to how i can achieve this? I can get a page attribute around every user, but i would like to be able to put it around every X number of users, if anyone has any ideas i would really appreciate the help. sorry for the length of this post.
thanks
|
|
|
|
|
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></xsl:text>
</xsl:when>
<xsl:otherwise>
<p><xsl:value-of select="position()"/>
<xsl:apply-templates/></p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
HTH,
Zdenek
"I would have written a shorter letter, but I didn’t have the time." [Blaise Pascal]
|
|
|
|
|
Hi all,
Trying to select some nodes (in script code),
i tried running this objNode.selectNodes("//NodeType[contains(@SomeAttribute,'SomeText')]")
when the browser (i.e. 6) runs the script, I get
msxml3.dll: Unknown method.
//NodeType[-->contains('@SomeAttribute'<--,'Test')]
Any ideas? According to the references, the contains function is implemented by MsXML3, is it not valid in this context???
|
|
|
|
|
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.
|
|
|
|
|
Hi guys, not well versed in XML here..
*** Update -- After reading a document on well formed XML, I realized that ampersands in XML attributes need to appear as & or the numeric code. Please Ignore this post. Thanks! ****
When I try to load the following XML string into a XmlDocument object (or IE for that matter)
<text>
<text3 pageUrl="cgi-bin/ubb/forumdisplay.cgi?action=topics&forum=General+NSX+Discussion&number=1&DaysPrune=1" />
</text>
I get the following error: [From IE]
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
A semi colon character was expected. Error processing resource 'file:///C:/VSProjects/WinForumProjects/WinForumInstallDirectory/ServerContentTest.xml'. Line 2, Position 65
The error occures right after the '&forum=' part of the attribute.
It would seem to be trying to parse the attribute as HTML or something. How can I get the object to ignore the actual values of the attribute?
Thanks
Jeff
|
|
|
|
|
Can you modify your post and turn off the html. Can not see the XML.
If you insist in finding evil in me you will find it, whether it is there or not.
|
|
|
|
|
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]
|
|
|
|
|
Hi all,
I just need some help with an XPath query. I have a document like
<my_items>
<item name="number 1">
...
</item>
<item name="number 2">
...
</item>
<!-- note the mis-spelling below -->
<item naem="number 3">
...
</item>
</my_items>
and I would like to get (from a pointer to my_items) all elements with a "name" attribute where the attribute is not empty. That would be item 1 and 2 above.
I've tried with a query like
_bstr_t bstrQuery = "item[(string-length(@name) > 0)]";
- but it doesn't work.
Got any hints ? I really need a useful resource for practical knowledge about XPath. All I've got is Essential XML Quick Reference by Aaron Skonnard and Martin Gudgin. It's definately good - but despite its humble size rather heavy I suppose a reference is supposed to be that though.
Well, thanks in advance for any help or pointers.
/Jan
|
|
|
|
|
make sure your using something newer than msxml2, which does not support string-length.
some resources:
http://www.w3.org/TR/xpath
http://www.vbxml.com/xsl/XPathRef.asp
http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/extras.html?stylesheetFile=XSLT/xpath.xslt&lang=eng
|
|
|
|
|
Thanks for the links - actually useful
I solved the problem yesterday by using @name != "" - but thanks anyway.
/Jan
|
|
|
|
|
correct way is
item[not(@name)]
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Dear all,
I try to select node from a XML file:
but always failed: there are nodes in the file
but the select result are no.
What wrong with my code or the structure/name of my XML file?
my code:
--------------------------
MSXML::IXMLDOMDocumentPtr pDoc = NULL;
MSXML::IXMLDOMElementPtr root;
MSXML::IXMLDOMNodePtr userParent, userNode;
MSXML::IXMLDOMNodeListPtr userList;
root = pDoc->documentElement;
userParent=root->selectSingleNode(_bstr_t("Users"));
strServer="gmitc-data3";
strVolume="d:\Shared Volume";
temp=strServer+"\\"+strVolume;
userList=userParent->selectNodes(_bstr_t\
("User[@Class1Root='"+temp+"']"));
for( int k=0; k<userList->Getlength(); k++)
{
m_nCount++;
userNode=userList->Getitem(k);
strUser=(LPCTSTR)_bstr_t(userNode->attributes\
->getNamedItem(_bstr_t("Name"))->text);
m_Grid.SetRows(m_nCount+1);
m_Grid.SetTextArray(m_nCols*m_nCount+2,strUser);
}// end for(userList)
---------------------------
my xml file:
---------------------------
<?xml version="1.0"?>"
<DMadmin>
<Class1BkupServer>
<Server Name="gmitc-data3" Full="No">
<SharedVolume Vol="d:\Shared Volume" Full="No"/>
</Server>
</Class1BkupServer>
<Class2BkupServer>
<Server Name="gmitc-data3" Full="No">
<SharedVolume Vol="d:\Shared Volume" Full="No"/>
</Server>
</Class2BkupServer>
<Users>
<User Name="laura" Quota="Basic" Department="" Location="" Phone="" Email=""
Class1Root="gmitc-data3\d:\Shared Volume" Class1Folder="laura_Class1_Data"
Class2Root="gmitc-data3\d:\Shared Volume" Class2Folder="laura_Class2_Data"/>
<User Name="ren" Quota="Middle" Department="" Location="" Phone="" Email=""
Class1Root="gmitc-data3\d:\Shared Volume" Class1Folder="ren_Class1_Data"
Class2Root="gmitc-data3\d:\Shared Volume" Class2Folder="ren_Class2_Data"/>
</Users>
</DMadmin>
---------------------------------
|
|
|
|
|
"User[@Class1Root='"+temp+"']" appears wrong at first glance, since all User tags are contained within the Users tag. thus, that xpath should read "Users/User[@Class1Root='"+temp+"']"
Also, you may want to develop on your local drive, and not over a network share. This eleminates a source of errors in your code, which may also be the reason.
* Edit: looking at your code (imagine that ), I see you retrieve the User tag at an earlier step, and then run the above xpath on that node. Perhaps ensure it works from a local file instead of a network share.
|
|
|
|
|
I got an idea from your opinion.
Thanks a lot.
|
|
|
|
|
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......
|
|
|
|
|
Hi!
I want to exclude an element from appearing within itself. I'm not sure if this is possible using XML Schema though. Can anyone clear this up for me please?
To exclude itself from appearing as a child I could use:
<xs:element name="person">
<xs:complexType>
<xs:element name="person" maxOccurs="0"/>
</xs:complexType>
</xs:element>
However, this doesn't exclude this element from appearing deeper in the hierarchy (e.g. as a grandchild) or does it? If not, is it possible?
Thanks
Jonnie
P.S. It may be apparent, that I'm a total newbie to XML Schema, but need to assess what is possible before diving in
|
|
|
|
|
Is there a way to make a heterogeneous XML/HTML file print like you'd wish it would? The following is XML, but our db person placed some HTML data in our data. It just prints like the html tags. I was hoping someone knew a fancy xsl thing. I just wish she had made it a separate note.
XML:
<specificnotes>
- <note>
<classification>U
<type>Undesignated
<note>Left/right.
- <note>
<classification>U
<type>Undesignated
<note>REQUIREMENTS
XSL Stylesheet uses default output method.
Thanks,
Lilian
|
|
|
|
|
Just in case anyone runs into this problem, here's the solution:
use the tag disable-output-escaping="yes" in your value of.
|
|
|
|
|
Hi, I have the following XSL code:
The set:distinct template from exslt.org:
<xsl:template name="set:distinct">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)" />
<xsl:otherwise>
<xsl:apply-templates select="$nodes[1][not(. = $nodes[position() > 1])]" mode="set:distinct"/>
<xsl:call-template name="set:distinct">
<xsl:with-param name="nodes" select="$nodes[position() > 1]" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
and the following call to it:
<xsl:variable name="distinctVnames">
<xsl:call-template name="set:distinct">
<xsl:with-param name="nodes" select="//@vname" />
</xsl:call-template>
</xsl:variable>
After this the call variable value is a string with all distinct vname attributes of my xml document. thats fine. But the vname attributes appear in the result string in document order.
Does anybody have an idea how to change this in order to obtain the vname attributes in alphabetical order? Thank you very much!
|
|
|
|
|
Hi!
Does anybody have XML Schemas for OWC 9 and 10?
Thanks,
Dmitry.
|
|
|
|
|
Could anyone give me any advice on how to convert a VARIANT data type to XML?
thanks
|
|
|
|
|
Could you be a little more explicit. For example do you have a VARIANT holding a string like <tag>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.
|
|
|
|