javascript xml xsl取值及数据修改_Xml教程
缂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾剧懓顪冪€n亝鎹i柣顓炴闇夐柨婵嗙墱閸ゅ绻涘顔荤凹闁哄懏绻堥弻娑氫沪閻愵剛娈ら梺鍛婃⒒閺佸摜妲愰幘瀛樺闁圭粯甯婃竟鏇㈡⒒娴d警鏀板ù婊庡墴椤㈡路閻涚S闂傚倸鍊搁崐宄懊归崶褏鏆﹂柣銏⑶圭粣妤呮煙閹殿喖顣奸柛瀣剁節閺屾洘寰勯崼婵嗗濠电偞鍨惰彜闁衡偓娴犲鍊甸柨婵嗗暙婵$兘鏌涚€n偅宕岀€规洘甯¢幃娆撳蓟閵夈儲鏆梻鍌欑閹碱偄煤閵娾晛纾婚柣鎰劋閸婂灚銇勯幒鍡椾壕闂佸疇顫夐崹鍧楀箖濞嗘挸鐭楀鑸瞪戦敍渚€姊绘担瑙勫仩闁告柨閰e畷浼村冀瑜滈崵鏇炩攽閻樺磭顣查柡鍛倐閺屻劑鎮ら崒娑橆伓濠电姷鏁告慨鐑藉极閹间礁纾婚柣鎰惈閸ㄥ倿鎮规潪鎷岊劅婵炲吋鐗犻幃宄扳枎韫囨搩浼€闂佺粯绻傞悥濂稿蓟濞戙垹鐒洪柛鎰典簴濡插牓姊虹紒妯诲鞍闁挎洏鍨藉濠氬灳閹颁礁鎮戦柟鑲╄ˉ閳ь剙纾鎴︽⒒娴g懓鈻曢柡鈧潏鈺傛殰闁跨喓濮撮拑鐔兼煏婵炵偓娅嗛柛瀣閺屾稓浠﹂崜褉妲堝銈呴獜閹凤拷 缂傚倸鍊搁崐鎼佸磹閹间礁纾瑰瀣捣閻棗銆掑锝呬壕闁芥ɑ绻堝娲敆閳ь剛绮旂€靛摜鐜绘俊銈呮噺閻撴瑩姊洪銊х暠濠⒀囩畺閺屻倝寮堕幐搴′淮闂佸搫鏈惄顖涗繆閻戠瓔鏁婇柣鎾冲瘨濞艰崵绱撻崒娆掝唹闁稿鎸搁…鍧楁嚋闂堟稑顫嶉梺缁樻尭閸熸挳寮婚弴鐔风窞闁割偅绻傞‖澶愭⒑缂佹ḿ绠ュù婊庝邯瀵鏁愰崨顏呮杸闂佸湱鍋撳ḿ娆擃敂閿燂拷 闂傚倸鍊搁崐鎼佸磹閹间礁纾瑰瀣椤愪粙鏌ㄩ悢鍝勑㈢痪鎯ь煼閺屾盯寮撮妸銉р偓顒勬煕閵夛絽濡界紓宥呮喘閺屽秹宕崟顐f濡炪倧瀵岄崹杈╂崲濠靛顫呴柨婵嗘閵嗘劙姊洪崫鍕⒈闁告挾鍠庨悾宄拔旈埀顒勩偑娴兼潙閱囬柣鏂挎惈楠炴劙姊绘担瑙勫仩闁稿寒鍨跺畷婵嗩吋婢跺鍓梺纭呮彧闂勫嫰鍩涢幒鎴唵閻犺櫣灏ㄩ崝鐔煎极閸儲鈷戦柛婵嗗椤箓鏌涙繝鍐ⅹ瀹€锝堝劵缁犳稑鈽夊Ο婧炬櫊閺屻劑寮崒婊冪濡炪們鍎茬粙鎾舵閹捐纾兼繛鍡樺灥婵′粙姊洪崫銉ヤ粶妞ゎ厾鍏橀悰顔跨疀濞戞瑦娅㈤梺璺ㄥ櫐閹凤拷 闂傚倸鍊搁崐鎼佸磹妞嬪海鐭嗗〒姘e亾妤犵偞鐗犻、鏇㈡晝閳ь剟鎮块鈧弻锝呂旈埀顒勬偋婵犲洤鐭楅煫鍥ㄧ⊕閻撴瑧绱撴担闈涚仼闁哄绋掓穱濠囨倷閹殿喚鐓撻梺鍝勫閳ь剚鍓氶崥瀣箹缁厜鍋撻懠顒佹櫦闂傚倷绀侀幉锟犮€冮崱娆忔瀳鐎广儱娲﹀畷鍙夌箾閹存瑥鐏╂鐐灪娣囧﹪顢涘┑鎰闂傚倸顦粔鎾煘閹达富鏁嬮柛鈩冪懅钃遍梻浣告啞濮婂綊銆冩繝鍥ф槬闁逞屽墯閵囧嫰骞掗幋婵囩亾濠电偛鍚嬮崝娆撳蓟閻旂⒈鏁婇柤娴嬫櫅閻撶喖鎮楃憴鍕婵炶尙鍠栧濠氬幢濡ゅ﹤鎮戦梺鍛婁緱閸ㄦ娊宕㈤鍕拻濞达綀濮ょ涵鍫曟煕閿濆繒鐣垫鐐茬箻閺佹捇鏁撻敓锟�,闂傚倸鍊搁崐鎼佸磹瀹勬噴褰掑炊椤掍礁鍓銈嗗姧缁犳垹绮堢€n偁浜滈柟鎵虫櫅閻忊晝鎮鈧缁樻媴缁涘娈┑顔斤公缁犳捇鏁愰悙鏉戠窞閻庯綆鍓涢鏇熺節閻㈤潧孝闁稿妫濆畷鐢稿即閵忥紕鍘卞銈嗗姧缁插墽绮堥埀顒傜磽娴f彃浜鹃梺鍛婂姀閺傚倹绂嶅⿰鍫熺厸闁稿本姘ㄦ禒銏ゆ煙椤旇棄鐏﹂柕鍥у缁犳盯寮撮悙瀵糕偓鍓х磽娴h櫣甯涢柣鈺婂灦閻涱喚鈧綆鍠楅崐鐑芥煛婢跺鐏╂繛鍫涘€濆缁樻媴閸涢潧缍婇、鏍幢濞戞ḿ顔夐梺鎼炲劀鐏炲墽绋侀梻浣告啞缁诲倻鈧皜鍥у嚑閹兼番鍔嶉悡娆愩亜閺嵮勵棞閻庢凹鍠楃粋宥夘敂閸啿鎷绘繛杈剧到閹诧繝宕悙鐑樼厽闁绘梹娼欓崝銈夋煙楠炲灝鐏╅摶锝呫€掑鐓庣仩婵炲牄鍔嶇换婵嬫偨闂堟刀锝囩棯閺夎法效鐎殿喗鐓¢獮鏍ㄦ媴閸︻厼寮抽梻浣虹帛濞叉牠宕愰崷顓涘亾濮樼偓瀚�!
推荐:jstl 字符串处理函数
最近用jstl1.0 的时候经常要在页面上对字符串做改动,在网上找了一个写的不错的,借鉴一下
<?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数据
<?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>
分享:XML 轻松学习手册(比较不错)
XML越来越热,关于XML的基础教程网络上也随处可见。可是一大堆的概念和术语往往让人望而生畏,很多朋友问我:XML到底有什么用,我们是否需要学习它?
相关Xml教程:
- 相关链接:
- 教程说明:
Xml教程-javascript xml xsl取值及数据修改
。