0

我想用特定的值替换标签值。它也可以多次出现。我的输入文件是 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>

我有所有要替换的国家/地区表列表。类似

   <field name="JobPost">Project Manager</field> replace with <JobPost>PM</JobPost>

我有所有可能的价值和它的替换代码。我一次有很多标签。我有点困惑,要么使用单独的 xml 文件进行查找,要么在 xslt 中只声明所有内容。我正在使用 xslt2.0。请建议我任何解决方案。

4

2 回答 2

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>
于 2013-08-13T07:53:55.123 回答
0

转换元素的主要转换是这样的:

<xsl:template match="//field">
  <xsl:element name="{local-name(@name)}"
    <xsl:value-of select="." />
  </xsl:element>
</xsl:template>
于 2013-08-13T07:54:13.853 回答