XSL conversion XML note

Source: Internet
Author: User
Tags xsl



I Love Tiananmen, Beijing


Sun rises on Tiananmen


Great leader Chairman Mao


Guide us forward


<P> & nbsp; <font size = "2"> in the past few days, students have gathered, moved, found, and worked, and have no time to learn and use blogs. <Br/> today, we can finally put everything in our hands. Let's talk about the XML knowledge I have used in my work over the past few days and how I feel about it. </Font> </P> <p> <font size = "2"> & nbsp; I used DOM to parse XML some time ago. In the past few days, I have to modify the </font> <font size = "2"> <br/> tree generated by an XML file because of my work. The original program uses XSL for parsing. I had to look at this stuff. </Font> </P>
<P> <font size = "2"> first, an XML file with a certain format is used, XML is generated by Java classes in a fixed format (production <br/> method omitted). The format is as follows: (provided tomorrow) <br/> parse the generated tree using the following file: (fytree. JS) <br/> function initialize () {<br/> & nbsp; var xmldoc <br/> & nbsp; vaR publish doc </font> </P> <p> <font size = "2"> & nbsp; xmldoc = new activexobject ('Microsoft. xmldom ') <br
/> & Nbsp; xmldoc. async = false; </font> </P> <p> <font size = "2"> & nbsp; latest Doc = new activexobject ('Microsoft. xmldom ') <br/> & nbsp; your doc. async = false; </font> </P> <p> <font size = "2"> & nbsp; xmldoc. load (document. all ("xmldata "). xmldocument) <br/> & nbsp; your doc. load (".. /tree/fytree. XSL ") <br
/> & Nbsp; <a href = "file: // alert"> file: // alert </a> (xmldoc.doc umentelement. transformnode (invalid DOC) <br/> & nbsp; foldertree. innerhtml = xmldoc.doc umentelement. transformnode (entity DOC) <br/>}</font> </P> <p> <font size = "2"> function clickonentity (entity) {<br/> & nbsp;
If (entity. open = "false") {<br/> & nbsp; expand (entity, true) <br/> & nbsp ;} <br/> & nbsp; else {<br/> & nbsp; collapse (entity) <br/> & nbsp ;} </font> </P> <p> <font size = "2"> & nbsp; clean () <br/> & nbsp; window. event. cancelbubble = "true" <br
/>}</Font> </P> <p> <font size = "2"> function expand (entity) {<br/> & nbsp; vaR oimage </font> </P> <p> <font size = "2"> & nbsp; oimage = entity. childnodes (0 ). all ["image"] <br/> & nbsp; oimage. src = entity. imageopen </font> </P> <p> <font size = "2"> & nbsp; for (I = 0; I & lt; entity. childnodes. length;
I ++) {<br/> & nbsp; If (entity. childnodes (I ). tagname = "Div") {<br/> & nbsp; entity. childnodes (I ). style. display = "Block" <br/> & nbsp; & nbsp ;}< br/> & nbsp; entity. open = "true" <br/>}& nbsp; </font> </P> <p> <font
Size = "2"> function getallcbxvalue (entity) {<br/> & nbsp; var STR = ""; <br/> & nbsp; var strtemp = ""; <br/> & nbsp; var arrstr; // split array <br/> & nbsp; var strdept = ""; <br/> & nbsp; vaR strcode = ""; </font> </P> <p> <font size = "2"> & nbsp; ocheckb = foldertree. childnodes (0 ). all ["checkb"]; </font> </P>
<P> <font size = "2"> <a href = "file: //"> file: // obtain </a> Department & amp; no. <br/> & nbsp; for (I = 0; I & lt; ocheckb. length; I ++) <br/> & nbsp ;{< br/> & nbsp; If (ocheckb [I]. checked) & nbsp; <br/> & nbsp; & nbsp ;{& nbsp; & nbsp; & nbsp; <a href = "file: // For example,"> file: // If the </a> check box is selected, <br
/> & Nbsp; strtemp = ocheckb [I]. value <br/> & nbsp; arrstr = strtemp. split ("Sep"); <br/> & nbsp; <a href = "file: // alert"> file: // alert </a> ("arrstr. length "+ arrstr. length); <br/> & nbsp; strdept = strdept + arrstr [0] + ";"; <br
/> & Nbsp; strcode = strcode + arrstr [1] + ";"; <br/> & nbsp; & nbsp; <br/> & nbsp; For (j = 0; J & lt; ocheckb. length; j ++) <br/> & nbsp; & nbsp ;{& nbsp; & nbsp; <a href = "file: // such as"> file: // If </a> is selected, all its subnodes are in the selected status. <br
/> & Nbsp; If (! Ocheckb [J]. checked) <br/> & nbsp; {// if no value is selected. <Br/> & nbsp; var abc = ocheckb [J]. value. split ("Sep"); <br/> & nbsp;
VaR ABCD = covertcrlftonull (arrstr [1]); <br/> & nbsp; <br/> & nbsp; if (covertcrlftonull (ABC [1]). substring (0, ABCD. length) = ABCD) <br/> & nbsp; {<br
/> & Nbsp; ocheckb [J]. checked = true; <br/> & nbsp ;} <br/> & nbsp; & nbsp ;}< br/> & nbsp; & nbsp; & nbsp ;}< br/> & nbsp; & nbsp ;}</font> </P>
<P> <font size = "2"> & nbsp; <br/> & nbsp ;} <br/> & nbsp; strcode = covertcrlftonull (strcode); <br/> & nbsp; setvalue (strdept, strcode ); <br/> & nbsp; <a href = "file: //"> file: // pass the </a> code to the past... <br/>}</font> </P> <p> <font size = "2"> Function
Covertcrlftonull (s) <br/> & nbsp; & nbsp ;{& nbsp; & nbsp; <a href = "file: //"> file: // cancel the </a> line break... <br/> & nbsp; var I; <br/> & nbsp; var S2 = s; <br/> & nbsp;
While (s2.indexof ("/R/N") & gt; 0) <br/> & nbsp; & nbsp ;{< br/> & nbsp; & nbsp; I = s2.indexof ("/R/N"); <br/> & nbsp; s2 = s2.substring (0, I) + s2.substring (I + 2, s2.length); <br/> & nbsp ;} <br/> & nbsp;
Return S2; <br/> & nbsp ;} </font> </P> <p> <font size = "2"> </font> & nbsp; </P> <p> <font size = "2"> function allcbxvalue (entity) {</font> </P> <p> <font size = "2"> <br/>}</font> </P> <p> <font size = "2"> <br/> function collapse (entity) {<br/> & nbsp; var oimage <br
/> & Nbsp; var I </font> </P> <p> <font size = "2"> & nbsp; oimage = entity. childnodes (0 ). all ["image"] <br/> & nbsp; oimage. src = entity. imageopen </font> </P> <p> <font size = "2"> & nbsp; for (I = 0; I & lt; entity. childnodes. length; I ++) {<br/> & nbsp;
If (entity. childnodes (I ). tagname = "Div") {<br/> & nbsp; If (entity. ID! = "Foldertree") entity. childnodes (I ). style. display = "NONE" <br/> & nbsp; collapse (entity. childnodes (I) <br/> & nbsp;
} <Br/> & nbsp; & nbsp ;}< br/> & nbsp; entity. open = "false" <br/>}</font> </P> <p> <font size = "2"> function expandall (entity) {<br/> & nbsp; var oimage <br/> & nbsp; vaR I </font> </P> <p> <font size = "2"> & nbsp; expand (entity, false) <br/> & nbsp; for (I = 0; I & lt; entity. childnodes. length;
I ++) {<br/> & nbsp; alert (foldertree. childnodes (I ). tagname); <br/> & nbsp; If (entity. childnodes (I ). tagname = "Div") {<br/> & nbsp; expandall (entity. childnodes (I) <br/> & nbsp; & nbsp ;}< br/> & nbsp ;} <br/>}</font> </P> <p> the preceding section mainly deals with click and double-click events. The following uses XSL and CSS to generate the desired format (fytree. XSL) <br
/> & Lt; XSL: stylesheet xmlns: XSL = "http://www.w3.org/TR/WD-xsl" Language = "JavaScript" & gt; </P> <p> & lt; XSL: template match = "Tree" & gt; <br/> & nbsp; & lt; XSL: Apply-templates select = "entity"/& gt; <br/> & lt; /XSL: Template & gt; </P> <p> & lt; XSL: template match = "entity" & gt; <br
/> & Nbsp; & lt; Div onclick = "clickonentity (this)" onselectstart = "Return false" ondragstart = "Return false" & gt; <br/> & nbsp; & lt; XSL: attribute name = "imageopen" & gt; & lt; XSL: value-of select = "imageopen"/& gt; & lt;/XSL: attribute & gt; <br/> & nbsp; & lt; XSL: attribute name = "checkb" & gt; & lt; XSL: value-
Select = "checkb"/& gt; & lt;/XSL: attribute & gt; <br/> & nbsp; & lt; XSL: attribute name = "open" & gt; false & lt;/XSL: attribute & gt; <br/> & nbsp; & lt; XSL: attribute name = "ID" & gt; F & lt; XSL: value-of select = "@ ID"/& gt; & lt;/XSL: attribute & gt; <br/> & nbsp; & lt; XSL: attribute name = "open" & gt; false & lt;/XSL: attribute & gt; <br
/> & Nbsp; & lt; XSL: attribute name = "oncontextmenu" & gt; window. event. cancelbubble = true; loadcontextmenu ('& lt; XSL: value-of select = "oncontextmenu"/& gt;'); Return false;
</XSL: attribute>
<XSL: attribute name = "style">
<XSL: If expr = "depth (this)> 2">
Display: none;
</XSL: If>
Padding-left: 20px;
Cursor: hand;
</XSL: attribute>
<Table border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<TD>
<Input type = "checkbox" id = "checkb" onclick = "javascript: getallcbxvalue (this)">
<XSL: attribute name = "value">
<XSL: value-of select = "checkb"/>
</XSL: attribute>
</Input>
</TD>
<TD valign = "Middle">

<XSL: attribute name = "src">
<XSL: value-of select = "image"/>
</XSL: attribute>
</Img>
</TD>
<TD valign = "Middle" nowrap = "true">
<XSL: attribute name = "style">
Padding-left: 7px;
Font-family: verdana;
Font-size: 11px;
Font-color: black;
</XSL: attribute>
<XSL: Choose>
<XSL: When test = "./href [@ url = 'y']">
<XSL: value-of select = "Description"/>
</XSL: When>
<XSL: otherwise>
<XSL: value-of select = "Description"/>
</XSL: otherwise>
</XSL: Choose>
</TD>
</Tr>
</Table>

<XSL: Apply-templates select = "Contents/entity"/>
</Div>
</XSL: Template>

</XSL: stylesheet>

Now I have moved back. Let's review the main functions of the two files tomorrow.

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.