|
Okay - I am fairly new to XSL and am trying to embed some JavaScript into an existing XSL stylesheet. The JS is to prevent the refresh from blinking. This is a really long post - just a warning!!
This is a sample of the XSL where I need to embed the script:
<xsl:template name="coursestats">
<xsl:param name="Round"/>
<xsl:variable name="CourseAcronym" select="@CourseAcronym"/>
<table border="0" cellpadding="0" cellspacing="0" background="/images/mybg.gif" width="642">
<tr>
<td width="1" bgcolor="Olive"> </td>
<td width="34" height="14" class="titClass">Hole</td>
<td width="1" bgcolor="Olive"> </td>
<td width="30" height="14" class="titClass">Par</td>
<td width="1" bgcolor="Olive"> </td>
<td width="54" height="14" class="titClass">Yardage</td>
<td width="1" bgcolor="Olive"> </td>
<td width="74" height="14" class="titClass">Scoring Avg</td>
<td width="1" bgcolor="Olive"> </td>
<td width="34" height="14" class="titClass">Rank</td>
<td width="1" bgcolor="Olive"> </td>
<td width="106" height="14" class="titClass">Avg Over/Under Par</td>
<td width="1" bgcolor="Olive"> </td>
<td width="40" height="14" class="titClass">Eagles</td>
<td width="1" bgcolor="Olive"> </td>
<td width="42" height="14" class="titClass">Birdies</td>
<td width="1" bgcolor="Olive"> </td>
<td width="38" height="14" class="titClass">Pars</td>
<td width="1" bgcolor="Olive"> </td>
<td width="54" height="14" class="titClass">Bogeys</td>
<td width="1" bgcolor="Olive"> </td>
<td width="82" height="14" class="titClass">Double Bogeys</td>
<td width="1" bgcolor="Olive"> </td>
<td width="54" height="14" class="titClass">Other</td>
<td width="1" bgcolor="Olive"> </td>
</tr>
<xsl:for-each select="Hole">
<xsl:sort select="@HoleNumber" order="ascending" data-type="number"/>
<tr> <td width="1" bgcolor="Olive"> </td>
<td width="34" height="14" class="txtClass"><xsl:value-of select="@HoleNumber"/></td> <td width="1" bgcolor="Olive"> </td>
<td width="30" height="14" class="txtClass"><xsl:value-of select="@Par"/></td> <td width="1" bgcolor="Olive"> </td>
<td width="54" height="14" class="txtClass"><xsl:value-of select="@PublishedYardage"/></td> <td width="1" bgcolor="Olive"> </td>
<xsl:variable name="numerand" select="Round[@Number = $Round]/ScoreN"/>
<xsl:variable name="operand" select="Round[@Number = $Round]/ScoreO"/>
<td width="74" height="14" class="txtClass">
<xsl:if test="$numerand != 0"><xsl:value-of select="format-number($operand div $numerand, '0.000')"/></xsl:if>
</td> <td width="1" bgcolor="Olive"> </td>
This is the start of the JS that I am using - it works in my HTML but when I try to embed into the XSL I only get the opening and closing JS tags for output:
<html><head>
<script language="JavaScript"> <!--
function makeChange() {
var newData = '';
// START DATA
newData += '<table border=0 cellpadding=0 cellspacing=0 background="/images/mybg.gif" width="642">';
newData += '<tr>';
newData += ' <td width="1" bgcolor="Olive"> </td>';
newData += ' <td width="34" height="14" class=titClass>Hole</td>';
newData += ' <td width="1" bgcolor="Olive"> </td>';
newData += ' <td width="30" height="14" class=titClass>Par</td>';
newData += ' <td width="1" bgcolor="Olive"> </td>';
newData += ' <td width="54" height="14" class=titClass>Yardage</td>';
newData += ' <td width="1" bgcolor="Olive"> </td>';
newData += ' <td width="74" height="14" class=titClass>Scoring Avg</td>';
newData += ' <td width="1" bgcolor="Olive"> </td>';
newData += ' <td width="34" height="14" class=titClass>Rank</td>';
newData += ' <td width="1" bgcolor="Olive"> </td>';
newData += ' <td width="106" height="14" class=titClass>Avg Over/Under Par</td>';
newData += ' <td width="1" bgcolor="Olive"> </td>';
I don't know if my problem is the newData+=' '.
Can anyone shed some light?
THANKS!
Julia
|
|
|
|
|
Simple - here's how you can embed JavaScript into an XSL document...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
...
<xsl:text disable-output-escaping="yes">
<![CDATA[
<script>
// your code goes here
</script>
]]>
</xsl:text>
...
</xsl:stylesheet>
HTH!
Essam - Author, JScript .NET Programming
...and a bunch of articles around the Web
|
|
|
|
|
Thanks - I'll give it a try.
Julia
|
|
|
|
|
I've been givin the task of developing a schema for some message formats. The formats are in XML and they all use common elements except for one. The group element is different for each of the messages. one message it may be of type lineGroup of another bitGroup. My question is how can I make my schema take either type group? I've found that one element name with 2 types does not work. So what is the work around? I'm new to this so if there is something I'm missing please fill me in. TIA.
example of the xml file (the <> were intentionally left out)
in one file...
group type="lineGroup"
name message1 /name
.
.
.
/group
In the other file
group type="bitGroup"
name message2 /name
.
.
.
/group
nay
|
|
|
|
|
This schema allows the attribute of the Group element names Type to be either LineGroup or BitGroup.
<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<xsd:element name = "Group">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref = "Name"/>
</xsd:sequence>
<xsd:attribute name = "Type" use = "required">
<xsd:simpleType>
<xsd:restriction base = "xsd:string">
<xsd:enumeration value = "LineGroup"/>
<xsd:enumeration value = "BitGroup"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name = "Name" type = "xsd:string"/>
</xsd:schema>
To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli
|
|
|
|
|
OK, this is probably me being stupid, but there are two things I want to do, and I can't seem to get them working:
- Insert special characters with the DOM
Some Unicode characters don't get encoded properly by the DOM. I've set the encoding to UTF-8, but when I set the Text property of a node to a string containing Unicode characters, they get replaced with "?". I've tried replacing them with the relevant "Π" , but that gets encoded as "&#x03A0;" ! Has anyone found a way to do this with the MSXML parser, or the .Net framework? - Query the default namespace with XPath
If I have an XML document with no namespace:
<?xml version='1.0'?>
<root>
<someNode>Item 1</someNode>
<someNode>Item 2</someNode>
<someNode>Etc...</someNode>
<root>
I can use oNode.selectNodes("//someNode") to select the "someNode" nodes.
If I have a namespace with a prefix:
<?xml version='1.0'?>
<trinet:root xmlns:trinet='http://www.trinet.co.uk/xml/Test.xsd'>
<trinet:someNode>Item 1</trinet:someNode>
<trinet:someNode>Item 2</trinet:someNode>
<trinet:someNode>Etc...</trinet:someNode>
<trinet:root>
I can use oNode.selectNodes("//trinet:someNode") .
But, if I have a default namespace:
<?xml version='1.0'?>
<root xmlns='http://www.trinet.co.uk/xml/Test.xsd'>
<someNode>Item 1</someNode>
<someNode>Item 2</someNode>
<someNode>Etc...</someNode>
<root>
oNode.selectNodes(""//someNode") returns nothing!
So far, the only solution I have found (in .Net) is to create an XMLNamespaceManager , add the default namespace as a namespace with a prefix, and then modify the XPath query to use the prefix, passing the XMLNamespaceManager object to every call to selectNodes or selectSingleNode .
Has anyone found a way to make the XPath query recognize the default namespace?
Thanks in advance.
Richard
|
|
|
|
|
Richard_D wrote:
Insert special characters with the DOM
There's something wrong on your system since XML supports Unicode characters. Make sure that your system supports the unicode characters you're inserting into the document. Assuming that you read the document into an editor to see the '?' marks in place of your unicode characters, make sure that the editor you use supports unicode files - Notepad on Windows 9x does not support Unicode whereas Notepad on Windows 2000 and XP supports it. If you're using 9x, open the file using something like XML Spy, which supports Unicode directly.
Richard_D wrote:
Query the default namespace with XPath
You've run into a very common problem with XPath 1.0. The specification is very confusing with regards to how vendors should handle the default namespace; as a result, vendors implement it differenly. The next incarnation of XPath is epxected address the problem.
In the mean time, your best option is to use a prefix as you did in your message's second listing. I suggest that you try to stick to that method since Microsoft could change their mind and cause your app to break when the next incarnation of XPath becomes a standard. Using namespace prefixes takes advantage of a standard, whereas the method you use (using the XMLNamespaceManager) is specific to Microsoft's XML parser and may not work in the future based on the direction of the wind and the state of evolving standards.
Essam - Author, JScript .NET Programming
...and a bunch of articles around the Web
|
|
|
|
|
Thanks for replying. I think I've solved the first problem - I needed to set the encoding to "ISO-8859-1" instead of "UTF-8". Now the only problem is to get the XMLHTTP object to recognize the correct code-page for non-XML documents.
As for XPath, I kind of suspected that this was the case. The other solution I found, which will only work for some XML documents, is to use the DataSet object to load the XML. Hopefully, this will continue to be supported as .Net evolves, regardless of the standards implemented.
Cheers,
Richard
|
|
|
|
|
Hi,
I have 2 very simple XML files. How would I compare them?
Thanks,
Vance
|
|
|
|
|
compare their structure or node values?
If the structure are the same, and you are using .NET - you can use something called XmlTextReader (or XmlNodeReader) call MoveNext(...) [or something like that] on both XML files and count differences.
would look like something like this...
while (...)
{
xml1.MoveNext(...);
xml2.MoveNext(...);
string x1 = xml1.value;
string x2 = xml2.value;
if (x1 != x2)
nDiffrenceCounter++;
}
Mike M
WinInsider.com
|
|
|
|
|
in order to know if they are different (without counting) you can compare the xml-strings:
in VB:
dim domFile1 as new DomDocument
dim domFile2 as new DomDocument
domFile1.load "C:\file1.xml"
domFile2.load "C:\file2.xml"
If domFile1.xml = domFile2.xml Then ....
what do you need?
Sebastian
|
|
|
|
|
There is a problem:
I have a HTML file with embedded XML document.
The document contains binary data within a tag.
...
...
<pictute>
FBYxVhUiQVGV0hcjMldhdZOl0dQ3gaSz0zNCRlNUdsI0NVVmkZS Q3GEobEINjhFSHKGgAIAQEAAD8A39ERERERERFx3a5Q2azV10qG
yOgoqeSokbGAXFrGlxAyQM4HrCoem9Wa9uFZZq+5aboXWC87jD1
GUunomEb43zFztpaWD+bjv7g7DHLvxHrNPXG7WC6U0B1DNKOz8F
..
..
..
This binary data is JPEG , that I want to display in web browser (namely IE)
the queston is :
How can I dispaly the image without saving it to disk file?
(Now I do it this way :
- save data to file on local disk drive
- set "src" attribute of an tag to the
location of the file
)
Thanx for any suggestions
Michal Januszczyk
|
|
|
|
|
You will have to write a program to decode the data, save it to a well-known location, and then set an img tag to point at it. That seems to be the only way...
|
|
|
|
|
.. I stumbled upon the following today I hope it helps.
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q254388
You shoudl be able to convert it to something useable.
Al.
Alice thought that running very fast for a long time would get you to somewhere else. " A very slow kind of country!" said the queen. "Now, here , you see, it takes all the running you can do, to keep in the same place".
|
|
|
|
|
When a space is given in .xml file, the value is not passed & it is not displayed in the browser.
|
|
|
|
|
Do you mean a whitespace character? If you want to show that, rather use  .
|
|
|
|
|
Can you provide an example. Where is the space character that it doesn't show up? Are you just opening the document, in say IE, or are you doing any processing of it?
|
|
|
|
|
Depending on which version of MSXML you have whitespace defaults are different.
In VC++ the following line will preserve the whitespaces if called prior to loading the file.
hr = pXML->put_preserveWhiteSpace(VARIANT_TRUE);
To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli
|
|
|
|
|
The FieldTypes type works fine in the Visual Studio.NET editor, but for some reason, I can't get the FileExtension type to work. Any ideas?
<xs:simpleType name="FieldTypes">
<xs:restriction base="xs:string">
<xs:enumeration value="Number" />
<xs:enumeration value="String" />
<xs:enumeration value="SSN" />
<xs:enumeration value="Money" />
<xs:enumeration value="Date" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="FileExtension">
<xs:restriction base="xs:string">
<xs:pattern value="\d{2}"/>
</xs:restriction>
</xs:simpleType>
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
The following checks ok for me:
<?xml version = "1.0" encoding = "UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" elementFormDefault = "qualified">
<xs:simpleType name="FieldTypes">
<xs:restriction base="xs:string">
<xs:enumeration value="Number" />
<xs:enumeration value="String" />
<xs:enumeration value="SSN" />
<xs:enumeration value="Money" />
<xs:enumeration value="Date" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="FileExtension">
<xs:restriction base="xs:string">
<xs:pattern value="\d{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
How are you defining your namespace? and or can you describe what you mean by not getting it to work?
To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli
|
|
|
|
|
Sorry. I was in a hurry to post this yesterday, as I was on my way out the door. I'm trying to validate that a file extension was correct. The '\d{2}' was just a test; the string I had in there originally was '\.\W{1,4}', which, if I remember correctly, means "a dot, followed by 1 to 4 non-whitespace charectors". My namespace is declared as you have it. In the Visual Studio.NET editor, if I type anything other than an enumeration member for the 'Type' attribute (declared as FieldType), I get the red squiggly line underneath. But the same is not true for an invalid file extension. I don't know. Back to the drawing board, I guess.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Jamie,
I really have not done much with patterns. But if I am reading the spec right, you need a small 'w' not a capital 'W'.
http://www.w3.org/TR/xmlschema-2/#rf-pattern
You have to have a slightly different setup for Visual Studio as mine lets me type anything in with no error checking.
To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli
|
|
|
|
|
I hate "why doesn't this work" posts but I'm at wits end.
Here's a snippet of my xml schema (I took off the angle brackets so it would show up).
msgIDType and TextFieldType are defined later in the file.
?xml version="1.0"?
xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsd:element name="message"
xsd:complexType
xsd:sequence
xsd:element name="msgID" type="msgIDType"
xsd:element name="TextField" type="TextFieldType"
/xsd:sequence
/xsd:complexType
/xsd:element
Now I'm using a simple validation script that is based on MSXML4 it returns this error...
Error: End tag 'xsd:sequence' does not match the start tag 'xsd:element'
I've checked all sequences and elements and each one has a matching end tag. I've also made sure that one doesn't begin before the other ends. So what else am I missing?
nay
|
|
|
|
|
If all you removed was the angle brakets then your "middle" xsd:elements are not terminated.
nay wrote:
xsd:element name="msgID" type="msgIDType"
xsd:element name="TextField" type="TextFieldType"
should be:
xsd:element name="msgID" type="msgIDType"/
xsd:element name="TextField" type="TextFieldType"/
And would give you the mentioned error.
To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli
|
|
|
|
|
Thanks for the reply! Unfortunately the code is at work so I cannot check it to see if that's what I did. I was sure I put the / on the end but who knows. It is the weekend so I'll worry about it on monday.
nay
|
|
|
|