乖,別哭的薄殼
~一份耕耘,一份收獲~
BlogJava
首頁
新隨筆
新文章
聯(lián)系
聚合
管理
posts - 23,comments - 260,trackbacks - 0
<
2009年3月
>
日
一
二
三
四
五
六
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(5)
給我留言
查看公開留言
查看私人留言
隨筆分類
CSS
HTML
Javascript(11)
java技術(6)
WEB相關(1)
個人日志
工具資料
數(shù)據(jù)庫(3)
精品收藏
隨筆檔案
2008年4月 (1)
2007年7月 (1)
2007年5月 (2)
2007年4月 (9)
2007年3月 (3)
2007年2月 (5)
2007年1月 (2)
好友的BLOG
crespo
同學,朋友,同事。。。匪夷所思
愛友
愛友的博客
神行梅
shenxingmei是個啥意思呢?
章章
!@#$%^&*()_+|
搜索
積分與排名
積分 - 67746
排名 - 800
最新評論
1.?re: java讀配置文件(xml、property)的簡單例子
正在學習如何讀取java 配置文件的方法,學習了
--一江
2.?re: javascript學習筆記(七)--DOM基礎
恐怕我也奪博主所愛了,呵呵,來個轉載
--楓中殘雪
3.?re: 關于復選框的驗證與jsp取值
兄弟,引用了你的代碼,謝謝了,但是JSP取值無法完成啊
--Pat
4.?re: 關于復選框的驗證與jsp取值
function checkData()中有個income數(shù)組,應該是answer吧,要不然驗證不了。
點了全選以后,A到F也勾選上了,但是當不勾選諸如B時,全選還在勾著。
--Pat
5.?re: xml+xsl+javascript取值及修改數(shù)據(jù)
恩,先看看能不能用,呵呵
--在線建模
閱讀排行榜
1.?java讀配置文件(xml、property)的簡單例子(11187)
2.?用jexcel讀寫excel的.xls文件的例子(9209)
3.?用sql實現(xiàn)遞歸(6318)
4.?xml+xsl+javascript取值及修改數(shù)據(jù)(4587)
5.?用ActiveXObject控件替換word書簽,將內(nèi)容導出到word后打印(4496)
評論排行榜
1.?java讀配置文件(xml、property)的簡單例子(17)
2.?添加Eclipse插件的簡單方法(13)
3.?mysql的中文亂碼問題(11)
4.?用jdbc操作數(shù)據(jù)庫的簡單例子(9)
5.?javascript學習筆記(三)--正則表達式 (7)
xml+xsl+javascript取值及修改數(shù)據(jù)
前幾天公司要用xml快速方便的存取屬性N多的數(shù)據(jù),跟
sinoly
合作研究了一下.做了一個小例子.
1.example.xml--主要數(shù)據(jù)文件
<?
xml version="1.0" encoding="UTF-8"
?>
<?
xml:stylesheet type="text/xsl" href="example.xsl"
?>
<
projects
id
="1"
>
<
project
title
="一級標題1"
index
="1"
>
<
items
isTrunk
="false"
title
="二級標題1.1"
id
="items_1"
>
<
result
type
="2"
>
1
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
<
remark
></
remark
>
</
items
>
<
items
isTrunk
="false"
title
="二級標題1.2"
id
="items_2"
>
<
result
type
="2"
>
3
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
items
>
</
project
>
<
project
title
="一級標題2"
index
="2"
>
<
items
isTrunk
="false"
title
="二級標題2.1"
id
="items_3"
>
<
result
type
="3"
>
3
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
items
>
<
items
isTrunk
="true"
title
="二級標題2.2"
>
<
item
title
="三級標題2.2.1"
id
="item_1"
>
<
result
type
="1"
>
2
</
result
>
<
officer
>
<![CDATA[
居然是亂碼
]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
item
>
<
item
title
="三級標題2.2.2"
id
="item_2"
>
<
result
type
="1"
>
3
</
result
>
<
officer
>
<![CDATA[
<><>
]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
item
>
</
items
>
<
items
isTrunk
="true"
title
="二級標題2.3"
>
<
item
title
="三級標題2.3.1"
id
="item_3"
>
<
result
type
="2"
>
1
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
item
>
<
item
title
="三級標題2.3.2"
id
="item_4"
>
<
result
type
="2"
>
1
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
item
>
</
items
>
</
project
>
<
project
title
="一級標題3"
index
="3"
>
<
items
isTrunk
="false"
title
="二級標題3.1"
id
="items_4"
>
<
result
type
="4"
units
="元"
>
25345
</
result
>
<
officer
>
<![CDATA[
sinoly
]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
items
>
<
items
isTrunk
="false"
title
="二級標題3.2"
id
="items_5"
>
<
result
type
="4"
units
="元"
>
9865764
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
items
>
<
items
isTrunk
="false"
title
="二級標題3.3"
id
="items_6"
>
<
result
type
="2"
>
0
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
items
>
<
items
isTrunk
="true"
title
="二級標題3.4"
>
<
item
title
="三級標題3.4.1"
id
="item_5"
>
<
result
type
="1"
>
0
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
item
>
<
item
title
="三級標題3.4.2"
id
="item_6"
>
<
result
type
="1"
>
0
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
item
>
<
item
title
="三級標題3.4.3"
id
="item_7"
>
<
result
type
="1"
>
0
</
result
>
<
officer
>
<![CDATA[]]>
</
officer
>
<
classified
>
1
</
classified
>
<
eligibility
>
0
</
eligibility
>
</
item
>
</
items
>
</
project
>
</
projects
>
2.example.xsl--樣式文件,很方便的取到xml數(shù)據(jù)
<?
xml version="1.0" encoding="gb2312"
?>
<
xsl:stylesheet
version
="1.0"
xmlns:xsl
="http://www.w3.org/1999/XSL/Transform"
>
<!--
根模板
-->
<
xsl:output
method
="xml"
/>
<
xsl:template
match
="/"
>
<
xsl:apply-templates
select
="projects/project"
/>
<
h6
>
<
button
type
="submit"
class
="btn1_mouseout"
onmouseover
="this.className='btn1_mouseover'"
onmouseout
="this.className='btn1_mouseout'"
title
="提交"
>
下一步
</
button
>
</
h6
>
</
xsl:template
>
<!--
主題模板
-->
<
xsl:template
match
="project"
>
<
TABLE
border
="0"
cellspacing
="0"
cellpadding
="0"
class
="table"
>
<
tr
>
<
td
colspan
="5"
align
="center"
class
="tright"
>
<
h2
>
<
xsl:number
value
="position()"
format
="一、"
/><
xsl:value-of
select
="@title"
/>
</
h2
>
</
td
>
</
tr
>
<
xsl:apply-templates
select
="items"
/>
</
TABLE
>
<
BR
/>
</
xsl:template
>
<!--
一級題干模板
-->
<
xsl:template
match
="items"
>
<
tr
>
<
td
colspan
="2"
class
="tright"
>
<
xsl:number
value
="position()"
format
="1."
/><
xsl:value-of
select
="@title"
/>
</
td
>
<
xsl:choose
>
<
xsl:when
test
="@isTrunk[.='false']"
>
<
xsl:apply-templates
select
="result"
/>
<
xsl:apply-templates
select
="officer"
/>
</
xsl:when
>
<
xsl:otherwise
>
<
td
colspan
="3"
class
="tright"
style
="color:blue;font-weight:bolder"
>
注意以下幾點
</
td
>
<
xsl:apply-templates
select
="item"
/>
</
xsl:otherwise
>
</
xsl:choose
>
</
tr
>
</
xsl:template
>
<!--
二級題干模板
-->
<
xsl:template
match
="item"
>
<
tr
>
<
td
class
="tright"
style
="padding-left:20px"
colspan
="2"
>
<
h4
><
xsl:number
value
="position()"
format
="(a)."
/><
xsl:value-of
select
="@title"
/></
h4
>
</
td
>
<
xsl:apply-templates
select
="result"
/>
<
xsl:apply-templates
select
="officer"
/>
</
tr
>
</
xsl:template
>
<!--
選擇框模板
-->
<
xsl:template
match
="result"
>
<
xsl:choose
>
<
xsl:when
test
="@type = '1'"
>
<
td
width
="15%"
>
<
xsl:element
name
="select"
>
<
xsl:attribute
name
="name"
>
re_
<
xsl:value-of
select
="../@id"
/></
xsl:attribute
>
<!--
<select name="select">
-->
<
xsl:choose
>
<
xsl:when
test
=".='0'"
>
<
option
value
="0"
selected
="selected"
>
請選擇
</
option
>
<
option
value
="1"
>
符合
</
option
>
<
option
value
="2"
>
基本符合
</
option
>
<
option
value
="3"
>
不符合
</
option
>
</
xsl:when
>
<
xsl:when
test
=".='1'"
>
<
option
value
="0"
>
請選擇
</
option
>
<
option
value
="1"
selected
="selected"
>
符合
</
option
>
<
option
value
="2"
>
基本符合
</
option
>
<
option
value
="3"
>
不符合
</
option
>
</
xsl:when
>
<
xsl:when
test
=".='2'"
>
<
option
value
="0"
>
請選擇
</
option
>
<
option
value
="1"
>
符合
</
option
>
<
option
value
="2"
selected
="selected"
>
基本符合
</
option
>
<
option
value
="3"
>
不符合
</
option
>
</
xsl:when
>
<
xsl:when
test
=".='3'"
>
<
option
value
="0"
>
請選擇
</
option
>
<
option
value
="1"
>
符合
</
option
>
<
option
value
="2"
>
基本符合
</
option
>
<
option
value
="3"
selected
="selected"
>
不符合
</
option
>
</
xsl:when
>
</
xsl:choose
>
<!--
</select>
-->
</
xsl:element
>
</
td
>
</
xsl:when
>
<
xsl:when
test
="@type = '2'"
>
<
td
width
="15%"
>
<
xsl:element
name
="select"
>
<
xsl:attribute
name
="name"
>
re_
<
xsl:value-of
select
="../@id"
/></
xsl:attribute
>
<
xsl:choose
>
<
xsl:when
test
=".='0'"
>
<
option
value
="0"
selected
="selected"
>
請選擇
</
option
>
<
option
value
="1"
>
是
</
option
>
<
option
value
="2"
>
否
</
option
>
</
xsl:when
>
<
xsl:when
test
=".='1'"
>
<
option
value
="0"
>
請選擇
</
option
>
<
option
value
="1"
selected
="selected"
>
是
</
option
>
<
option
value
="2"
>
否
</
option
>
</
xsl:when
>
<
xsl:when
test
=".='3'"
>
<
option
value
="0"
>
請選擇
</
option
>
<
option
value
="1"
>
是
</
option
>
<
option
value
="2"
selected
="selected"
>
否
</
option
>
</
xsl:when
>
</
xsl:choose
>
</
xsl:element
>
</
td
>
</
xsl:when
>
<
xsl:when
test
="@type = '3'"
>
<
td
width
="15%"
>
<
xsl:element
name
="select"
>
<
xsl:attribute
name
="name"
>
re_
<
xsl:value-of
select
="../@id"
/></
xsl:attribute
>
<
xsl:choose
>
<
xsl:when
test
=".='0'"
>
<
option
value
="0"
selected
="selected"
>
請選擇
</
option
>
<
option
value
="1"
>
有
</
option
>
<
option
value
="2"
>
無
</
option
>
</
xsl:when
>
<
xsl:when
test
=".='1'"
>
<
option
value
="0"
>
請選擇
</
option
>
<
option
value
="1"
selected
="selected"
>
有
</
option
>
<
option
value
="2"
>
無
</
option
>
</
xsl:when
>
<
xsl:when
test
=".='3'"
>
<
option
value
="0"
>
請選擇
</
option
>
<
option
value
="1"
>
有
</
option
>
<
option
value
="2"
selected
="selected"
>
無
</
option
>
</
xsl:when
>
</
xsl:choose
>
</
xsl:element
>
</
td
>
</
xsl:when
>
<
xsl:otherwise
>
<
td
width
="15%"
>
<
xsl:element
name
="textarea"
>
<
xsl:attribute
name
="name"
>
re_
<
xsl:value-of
select
="../@id"
/></
xsl:attribute
><
xsl:value-of
select
="."
/>
</
xsl:element
>
<
xsl:value-of
select
="@units"
/>
</
td
>
</
xsl:otherwise
>
</
xsl:choose
>
</
xsl:template
>
<!--
責任人模板
-->
<
xsl:template
match
="officer"
>
<
td
width
="9%"
class
="tright"
>
責任人
</
td
>
<
td
width
="11%"
>
<
xsl:element
name
="textarea"
>
<
xsl:attribute
name
="name"
>
of_
<
xsl:value-of
select
="../@id"
/></
xsl:attribute
>
<
xsl:value-of
select
="."
/>
</
xsl:element
>
</
td
>
</
xsl:template
>
</
xsl:stylesheet
>
3.index.html--用javascript導入數(shù)據(jù)并能修改xml里的數(shù)據(jù).
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
/>
<
title
>
測試
</
title
>
</
head
>
<
link
rel
="Stylesheet"
type
="text/css"
href
="focusform.css"
/>
<
script
language
="javascript"
src
="form.js"
></
script
>
<
script
type
="text/javascript"
src
="detect.js"
></
script
>
<
script
type
="text/javascript"
src
="xmldom.js"
></
script
>
<
script
type
="text/javascript"
>
//
載入xml與xsl文件
var
oxml
=
new
XmlDom();
var
oxsl
=
new
XmlDom();
oxml.async
=
false
;
//
同步載入
oxsl.async
=
false
;
oxml.load(
"
example.xml
"
);
oxsl.load(
"
example.xsl
"
);
if
(oxml.parseError
!=
0
)
{
var
oError
=
oxml.parseError;
alert(
"
An error occurred:\nError Code:
"
+
oError.errorCode
+
"
\n
"
+
"
Line:
"
+
oError.line
+
"
\n
"
+
"
Line Pos:
"
+
oError.linepos
+
"
\n
"
+
"
Reason:
"
+
oError.reason);
}
if
(oxsl.parseError
!=
0
)
{
var
oError
=
oxsl.parseError;
alert(
"
An error occurred:\nError Code:
"
+
oError.errorCode
+
"
\n
"
+
"
Line:
"
+
oError.line
+
"
\n
"
+
"
Line Pos:
"
+
oError.linepos
+
"
\n
"
+
"
Reason:
"
+
oError.reason);
}
var
sResult
=
oxml.transformNode(oxsl);
//
alert(sResult);
//
一些操作
function
btnSub()
{
var
fes
=
document.forms[
0
].elements;
for
(
var
i
=
0
;i
<
fes.length;i
++
)
{
var
name
=
fes[i].name;
if
(name.indexOf('re_')
!=-
1
)
{
var
xmlid
=
name.substring(
3
,name.length);
var
obj;
//
= oxml.getElementById("items_1");//xml的dom里沒有這個方法?
var
oItems1
=
oxml.getElementsByTagName(
"
items
"
);
//
也可以用xpath實現(xiàn)。
var
oItems2
=
oxml.getElementsByTagName(
"
item
"
);
for
(
var
j
=
0
;j
<
oItems1.length;j
++
)
{
if
(oItems1[j].getAttribute('id')
==
xmlid)
{
obj
=
oItems1[j];
break
;
}
}
for
(
var
j
=
0
;j
<
oItems2.length;j
++
)
{
if
(oItems2[j].getAttribute('id')
==
xmlid)
{
obj
=
oItems2[j];
break
;
}
}
if
(obj)
{
obj.childNodes[
0
].text
=
fes[i].value;
}
else
{
alert(
"
在xml中未找到id為
"
+
xmlid
+
"
的items或item
"
);
}
}
if
(name.indexOf('of_')
!=-
1
)
{
var
xmlid
=
name.substring(
3
,name.length);
var
oItems1
=
oxml.getElementsByTagName(
"
items
"
);
var
oItems2
=
oxml.getElementsByTagName(
"
item
"
);
for
(
var
j
=
0
;j
<
oItems1.length;j
++
)
{
if
(oItems1[j].getAttribute('id')
==
xmlid)
{
obj
=
oItems1[j];
break
;
}
}
for
(
var
j
=
0
;j
<
oItems2.length;j
++
)
{
if
(oItems2[j].getAttribute('id')
==
xmlid)
{
obj
=
oItems2[j];
break
;
}
}
if
(obj)
{
obj.childNodes[
1
].text
=
fes[i].value;
}
else
{
alert(
"
在xml中未找到id為
"
+
xmlid
+
"
的items或item
"
);
}
}
}
alert(oxml.xml);
//
alert(oxml.childNodes[2].xml);
return
false
;
}
</
script
>
</
head
>
<
body
>
<
form
name
="form1"
action
="test.jsp"
method
="post"
onsubmit
="return btnSub();"
>
<
script
type
="text/javascript"
>
document.write(sResult);
</
script
>
</
form
>
</
body
>
</
html
>
需要用到的輔助文件
4.focusform.css--樣式文件
5.form.js文本框的效果
6.detect.js--瀏覽器及操作系統(tǒng)識別(取自javascript高級程序設計)
7.xmldom.js--不同瀏覽器xml操作統(tǒng)一(取自javascript高級程序設計)
下載地址
posted on 2007-07-07 00:12
小祝
閱讀(4587)
評論(7)
編輯
收藏
所屬分類:
Javascript
FeedBack:
#
re: xml+xsl+javascript取值及修改數(shù)據(jù)
2007-07-08 11:14 |
sinoly
汗一個。呵呵。。。
是不是可以找你要點費用?貌似有部分我的代碼哦:)
ps:北漂對你們是一種歷練,有需要的時候給我電話就好。我想,北京怎么我還能活動一下的
回復
更多評論
#
re: xml+xsl+javascript取值及修改數(shù)據(jù)
2007-07-08 15:43 |
小祝
@sinoly
呵呵,我又不是拿來商業(yè)目的,開源的。。。給你留個名好了,呵呵~
先謝謝了,我還是先找找看了,不行再找你幫忙,呵呵~
回復
更多評論
#
re: xml+xsl+javascript取值及修改數(shù)據(jù)
2007-07-08 16:40 |
飄搖
看見代碼就頭疼
回復
更多評論
#
re: xml+xsl+javascript取值及修改數(shù)據(jù)
2007-07-10 10:48 |
sinoly
@小祝
呵呵,我開個玩笑咯。。。
不過經(jīng)過這一次的處理,堅定了我以后在項目中使用統(tǒng)一xml處理方式的想法了。以前最為頭痛的統(tǒng)計對服務器的負載問題現(xiàn)在轉移到了客戶端,而服務器僅僅只進行數(shù)據(jù)規(guī)整,感覺應該是處理之道吧
回復
更多評論
#
re: xml+xsl+javascript取值及修改數(shù)據(jù)
2009-03-28 16:18 |
sdjl
下載不了
回復
更多評論
#
re: xml+xsl+javascript取值及修改數(shù)據(jù)
2009-03-31 08:58 |
小祝
@sdjl
不好意思,blogjava把這個文件弄丟失了,我這也沒備份了,
detect.js 和 xmldom.js 在我的博文 《javascript學習筆記(六)--資料》里有,另外兩個其實無關緊要,有沒有都無所謂,只是樣子難看了點~~~
回復
更多評論
#
re: xml+xsl+javascript取值及修改數(shù)據(jù)
2010-05-14 12:54 |
在線建模
恩,先看看能不能用,呵呵
回復
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
用ActiveXObject控件替換word書簽,將內(nèi)容導出到word后打印
xml+xsl+javascript取值及修改數(shù)據(jù)
javascript學習筆記(八)--錯誤處理
javascript學習筆記(七)--DOM基礎
javascript學習實踐--新手上路--驗證表單
javascript學習筆記(六)--資料
javascript學習筆記(五)--事件
javascript學習筆記(四)--檢測瀏覽器和操作系統(tǒng)
javascript學習筆記(三)--正則表達式
javascript學習筆記(二)--繼承
Copyright ©2025 小祝 Powered By
博客園
模板提供:
滬江博客
主站蜘蛛池模板:
成人毛片免费网站
|
h片在线免费观看
|
久久99精品免费视频
|
99久热只有精品视频免费看
|
亚洲一级免费毛片
|
国产精品久免费的黄网站
|
999久久久免费精品国产
|
成人免费男女视频网站慢动作
|
免费国产小视频在线观看
|
亚洲中文字幕无码中文字在线
|
久久久久亚洲av无码专区导航
|
亚洲国产日韩视频观看
|
免费国产黄网站在线看
|
日韩在线永久免费播放
|
天天摸夜夜摸成人免费视频
|
亚洲av无码乱码国产精品fc2
|
亚洲国产精品网站久久
|
偷自拍亚洲视频在线观看
|
免费一区二区无码东京热
|
免费精品人在线二线三线区别
|
亚洲毛片av日韩av无码
|
亚洲精品美女在线观看
|
黄页网址在线免费观看
|
免费国产叼嘿视频大全网站
|
免费看的黄色大片
|
亚洲国产成人片在线观看
|
2020天堂在线亚洲精品专区
|
亚洲精品黄色视频在线观看免费资源
|
成人黄18免费视频
|
中文字幕在亚洲第一在线
|
亚洲免费网站在线观看
|
一级美国片免费看
|
在线视频免费观看高清
|
国产aⅴ无码专区亚洲av麻豆
|
亚洲依依成人精品
|
国产乱子伦精品免费视频
|
最新仑乱免费视频
|
亚洲av无码片在线播放
|
成a人片亚洲日本久久
|
久久www免费人成看片
|
国产精品亚洲视频
|