使用xslt修改xml文件 [英] modify xml file using xslt
本文介绍了使用xslt修改xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的xml文件(Hospitals.xml)
<? xml version = 1.0 编码 = UTF-8 standalone = 是 ? >
< 医院 >
< hospital >
< department < span class =code-keyword>>
< 诊所 >
< cid > 31 < / cid >
< clinicName > c7 < / clinicName >
< status > 0 < / status >
< / clinic >
< 诊所 >
< cid > 32 < / cid >
< clinicName > c2 < / clinicName >
< < span class =code-leadattribute> status > 0 < / status >
< < span class =code-leadattribute> / clinic >
< depId > 21 < < span class =code-leadattribute> / depId >
< departmentName > 卡< < span class =code-leadattribute> / departmentName >
< / department >
< hospId > 11 < / hospId < span class =code-keyword>>
< hospitalName > aaa < / hospitalName < span class =code-keyword>>
< / hospital >
< hospital >
< department >
< 诊所 >
< cid > 33 < / cid >
< clinicName > c3 < / clinicName >
< 状态 > 0 < / status >
< / clinic >
< 诊所 >
< cid > 34 < / cid >
< clinicName > c4 < / clinicName >
< 状态 > 0 < / status >
< / clinic >
< depId > 22 < / depId >
< departmentName > eye < / departmentName >
< / department >
< department >
< 诊所 >
< cid > 36 < span class =code-keyword>< / cid >
< clinicName > c1 < span class =code-keyword>< / clinicName >
< status > 0 < span class =code-keyword>< / status >
< / clinic >
< depId > 24 < / depId >
< departmentName > mental < / departmentName >
< / department >
< < span class =code-leadattribute> hospId > 12 < / hospId >
< hospitalName > bbbb < / hospitalName >
< / hospital >
< hospital >
< department < span class =code-keyword>>
< 诊所 >
< cid > 30 < / cid >
< span class =code-keyword>< clinicName > c6 < / clinicName >
< span class =code-keyword>< status > 0 < / status >
< span class =code-keyword>< / clinic >
< 诊所 >
< cid > 35 < / cid >
< clinicName > c5 < / clinicName >
< 状态 > 0 < / status >
< / clinic >
< depId > 23 < / depId >
< departmentName > dental < / departmentName >
< / department >
< hospId > 13 < / hospId >
< hospitalName > cccc < / hospitalName >
< / hospital >
< 医院 >
< 部门 >
< span class =code-keyword>< 诊所 >
< cid > 37 < / cid >
< clinicName > c8 < / clinicName >
< status > 0 < / status >
< / clinic >
< depId > 25 < / depId >
< departmentName > test < / departmentName >
< / department >
< hospId > 14 < / hospId >
< hospitalName > ddd < / hospitalName >
< / hospital >
< ; / hospital >
当我根据我选择的诊所时,我需要更改状态字段的值
我试过这样
< xsl:stylesheet version =1.0xmlns:xsl =http:// www .w3.org / 1999 / XSL / Transform>
< xsl:output omit-xml-declaration = yes 缩进 = 是 / >
< xsl :带状空间跨度> <温泉n class =code-attribute> elements = * / >
< span class =code-keyword>< xsl:param name = hospId / >
< xsl:param name = depId / >
< xsl:param name = clinicId / >
< xsl:template 匹配 = node()| @ * >
< xsl:copy >
< xsl:apply-templates 选择 = node()| @ * / >
< / xsl:copy >
< / xsl:template >
< span class =code-keyword>< xsl:template 匹配 = 医院/医院[hospId ='$ hospId'] / department [depId ='$ depId'] /诊所[cid ='$ clinicId'] / status >
< / status > 123 < / status >
< / xsl:template >
< / xsl:stylesheet >
给出一些错误请帮助我..提前谢谢
解决方案
hospId '] /部门[DEPID ='
DEPID '] /诊所[CID ='
clinicId'] /状态 >
< / status > 123 < / status >
< / xsl:template >
< / xsl:stylesheet >
给出一些错误请帮帮我..谢谢提前
This is my xml file (Hospitals.xml)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<hospitals>
<hospital>
<department>
<clinic>
<cid>31</cid>
<clinicName>c7</clinicName>
<status>0</status>
</clinic>
<clinic>
<cid>32</cid>
<clinicName>c2</clinicName>
<status>0</status>
</clinic>
<depId>21</depId>
<departmentName>card</departmentName>
</department>
<hospId>11</hospId>
<hospitalName>aaa</hospitalName>
</hospital>
<hospital>
<department>
<clinic>
<cid>33</cid>
<clinicName>c3</clinicName>
<status>0</status>
</clinic>
<clinic>
<cid>34</cid>
<clinicName>c4</clinicName>
<status>0</status>
</clinic>
<depId>22</depId>
<departmentName>eye</departmentName>
</department>
<department>
<clinic>
<cid>36</cid>
<clinicName>c1</clinicName>
<status>0</status>
</clinic>
<depId>24</depId>
<departmentName>mental</departmentName>
</department>
<hospId>12</hospId>
<hospitalName>bbbb</hospitalName>
</hospital>
<hospital>
<department>
<clinic>
<cid>30</cid>
<clinicName>c6</clinicName>
<status>0</status>
</clinic>
<clinic>
<cid>35</cid>
<clinicName>c5</clinicName>
<status>0</status>
</clinic>
<depId>23</depId>
<departmentName>dental</departmentName>
</department>
<hospId>13</hospId>
<hospitalName>cccc</hospitalName>
</hospital>
<hospital>
<department>
<clinic>
<cid>37</cid>
<clinicName>c8</clinicName>
<status>0</status>
</clinic>
<depId>25</depId>
<departmentName>test</departmentName>
</department>
<hospId>14</hospId>
<hospitalName>ddd</hospitalName>
</hospital>
</hospitals>
I need to change the value of status field when I based on the clinic I have selected
I tried like this
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="hospId" />
<xsl:param name="depId" />
<xsl:param name="clinicId" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="hospitals/hospital[hospId='$hospId']/department[depId='$depId']/clinic[cid='$clinicId']/status">
</status>123</status>
</xsl:template>
</xsl:stylesheet>
its giving some error please help me..Thanks in advance
解决方案
hospId']/department[depId='
depId']/clinic[cid='
clinicId']/status"> </status>123</status> </xsl:template> </xsl:stylesheet>
its giving some error please help me..Thanks in advance
这篇关于使用xslt修改xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文