xslt 解析
xml文件
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<NaturalPerson>
<Title>MR</Title>
<Gender>M</Gender>
</NaturalPerson>
<NaturalPerson>
<Title>MI</Title>
<Gender>F</Gender>
</NaturalPerson>
</Data>
<?xml version="1.0" encoding="UTF-8"?>
<TR04_NATURAL_PERSON>
<cstd_gender>M</cstd_gender>
<cstd_title>MR</cstd_title>
</TR04_NATURAL_PERSON>
<TR04_NATURAL_PERSON>
<cstd_gender>F</cstd_gender>
<cstd_title>MI</cstd_title>
</TR04_NATURAL_PERSON>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="//NaturalPerson">
<!--<xsl:for-each select="//NaturalPerson">-->
<xsl:for-each select="child::*">
<TR04_NATURAL_PERSON>
<xsl:if test="local-name()='Title'">
<xsl:variable name="eleName" select="//Gender"/>
<cstd_gender><xsl:value-of select="$eleName/text()"/></cstd_gender>
</xsl:if>
<xsl:if test="local-name()='Gender'">
<xsl:variable name="eleName" select="//Title"/>
<cstd_title><xsl:value-of select="$eleName/text()"/></cstd_title>
</xsl:if>
</TR04_NATURAL_PERSON>
</xsl:for-each>
<!--</xsl:for-each> -->
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<TR04_NATURAL_PERSON>
<cstd_gender>M</cstd_gender>
</TR04_NATURAL_PERSON>
<TR04_NATURAL_PERSON>
<cstd_title>MR</cstd_title>
</TR04_NATURAL_PERSON>
<TR04_NATURAL_PERSON>
<cstd_gender>M</cstd_gender>
</TR04_NATURAL_PERSON>
<TR04_NATURAL_PERSON>
<cstd_title>MR</cstd_title>
</TR04_NATURAL_PERSON>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="Data/NaturalPerson">
<TR04_NATURAL_PERSON>
<cstd_gender><xsl:value-of select="Gender"/></cstd_gender>
<cstd_title><xsl:value-of select="Title"/></cstd_title>
</TR04_NATURAL_PERSON>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>