function ChangeIDToString(strCondition,id)
{
if (strCondition.indexOf("AssignedTo") > -1)
return GetUserName(id)
else if (strCondition.indexOf("ClaimStatusId") > -1)
return GetClaimStatus(id)
else if (strCondition.indexOf("ClaimTypeId") > -1)
return GetClaimType(id);
else
return id;
}
注意:三个学生姓名(Name1,Name2,Name3)目前不属于类元素。我也声明了一个变量,我存储学生姓名的值。请给我建议我怎么能得到这个或我做错了
答案 0 :(得分:0)
鉴于以下格式良好的输入:
<强> XML 强>
<v2:College xmlns:v2="http://example.com/v2">
<v2:Student>Name1</v2:Student>
<v2:Student>Name2</v2:Student>
<v2:Student>Name3</v2:Student>
<v2:Teacher>
<v2:Class>
<v2:Subject>ABC</v2:Subject>
</v2:Class>
</v2:Teacher>
</v2:College>
以下样式表:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:v2="http://example.com/v2">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="v2:Class">
<xsl:copy>
<xsl:apply-templates/>
<xsl:copy-of select="/v2:College/v2:Student"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
将返回:
<强>结果强>
<?xml version="1.0" encoding="UTF-8"?>
<v2:College xmlns:v2="http://example.com/v2">
<v2:Student>Name1</v2:Student>
<v2:Student>Name2</v2:Student>
<v2:Student>Name3</v2:Student>
<v2:Teacher>
<v2:Class>
<v2:Subject>ABC</v2:Subject>
<v2:Student>Name1</v2:Student>
<v2:Student>Name2</v2:Student>
<v2:Student>Name3</v2:Student>
</v2:Class>
</v2:Teacher>
</v2:College>
将"http://example.com/v2"
替换为XML使用的实际命名空间。