我想用一个特定的值替换标签值。它也是有意义的,它在那里呈现多次。 我的输入文件是sample.xml
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:getDocumentByKeyResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.taleo.com/ws/integration/toolkit/2005/07"><Document xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07"><Attributes><Attribute name="duration">0:00:06.654</Attribute><Attribute name="count">113</Attribute><Attribute name="entity">Requisition</Attribute><Attribute name="mode">XML</Attribute><Attribute name="version">http://www.taleo.com/ws/tee800/2009/01</Attribute></Attributes><Content>
<ExportXML xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<record>
<field name="JobAction">2</field>
<field name="JobType">false</field>
<field name="JobPositionPostingID">000065</field>
<field name="Website"/>
<field name="HiringOrgName">HIRING Division</field>
<field name="SummaryText"/>
<field name="FormattedName">AdityaNath</field>
<field name="JobPositionTitle">Project Manager</field>
<field name="JobIndustryCode"/>
<field name="JobFunctionCode">ADMINISTRATION</field>
<field name="JobRoleCode"/>
<field name="JobKeyword">To provide administrative and information support to the HOD.</field>
<field name="Location">India</field>
<field name="SalaryCurrency">Indian Rupee (INR)</field>
<field name="MinimumSalary">200000.0</field>
<field name="MaximumSalary">400000.0</field>
<field name="summaryText1">Bachelor's degree</field>
<field name="MinimumExperiance">2</field>
<field name="MaximumExperiance">4</field>
<field name="UGQualifications"/>
<field name="UGSpecializations">BACHELOR_S_DEGREE_16_YEARS</field>
<field name="Email">AswaniAlekhya.Ugranam@lntinfotech.com</field>
</record>
</ExportXML></Content></Document></ns1:getDocumentByKeyResponse></soapenv:Body></soapenv:Envelope>
我已经替换了代码 标签
<field name="Location">India</field> with <Location>IND</Location>
<field name="Location">United State</field> with <Location>US</Location>
我有所有国家/地区表格列表以替换.similary
<field name="JobPost">Project Manager</field> replace with <JobPost>PM</JobPost>
我拥有所有可能的价值及其替换代码。我一次只能放置许多标签。 我有点困惑,要么使用seprate xml文件进行查找,要么在xslt中只声明一切。我正在使用xslt2.0.please建议我解决。
答案 0 :(得分:0)
您知道要转换的字段的名称吗?在这种情况下,您只需使用
<xsl:param name="locs">
<map>
<location from="India" to="IND"/>
<location from="United States" to="US"/>
</map>
</xsl:param>
<xsl:key name="new-loc" match="map/location" use="@from"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="field[@name = 'Location']">
<xsl:element name="{@name}">
<xsl:value-of select="key('new-loc', ., $locs)/@to"/>
</xsl:element>
</xsl:template>
答案 1 :(得分:0)
转换元素的主要转换是:
<xsl:template match="//field">
<xsl:element name="{local-name(@name)}"
<xsl:value-of select="." />
</xsl:element>
</xsl:template>