如何将值从xml映射到XSLT



我正在尝试将数据从xml填充到xslt,但由于我不知道xslt和xpath,所以无法做到这一点。尽管我尽了最大的努力(使用了concat((方法(,但还是做不到。你能帮我做下面的地图吗?:----

Xml:----(一段代码(

<supportingProductFeatures>
<type>NH</type>
<version>2.0.0</version>
<capacityAvailability>
<featureType>TY1</featureType>
<capacity>2</capacity>
<unitOfMeasure>Mbps</unitOfMeasure>
<highSpeedNotLessThan>true</highSpeedNotLessThan>
</capacityAvailability>
</supportingProductFeatures>

尝试实现以下目标:--

<DescribedBy>
<value>Yes</value> 
<Characteristic>
<name>NH TY1 High Speed Tiers (greater or equal to 2Mbps)</name> 
<type>abcd</type>
</Characteristic>
</DescribedBy>

映射条件:---

if ((highSpeedNotLessThan!=null))
{
if(highSpeedNotLessThan.equals("true"){

1) set value=yes
2) set name=concat(type +" "+featureType+" "+"High Speed Tiers (greater or equal to 
"+capacity+unitOfMeasure+")"
3)  set type="abcd"
}
else if(highSpeedNotLessThan.equals("false"){

1)set value=no
2) set name=concat(type +" "+featureType+" "+"High Speed Tiers (greater or equal to 
"+capacity+unitOfMeasure+")"
3)  set type="abcd"
}
}

这就是我迄今为止所尝试的:——

<DescribedBy>
<xsl:if test="/supportingProductFeatures/capacityAvailability/highSpeedNotLessThan='true'">
<value>yes</value>
</xsl:if>
<xsl:if test="/supportingProductFeatures/capacityAvailability/highSpeedNotLessThan='false'">
<value>No</value>
</xsl:if>
<Characteristic>
<name>
<xsl:value-of select="concat(supportingProductFeatures/type,' ',supportingProductFeatures/capacityAvailability/featureType,' ','High Speed Tiers (greater or equal to ',supportingProductFeatures/capacityAvailability/capacity,supportingProductFeatures/capacityAvailability/unitOfMeasure)" />
</name> 
<type>abcd</type>
</Characteristic>
</DescribedBy>

以下是使用XSLT的方法。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<Output>
<xsl:apply-templates select="//supportingProductFeatures"/>
</Output>
</xsl:template>

<xsl:template match="supportingProductFeatures">
<DescribedBy>
<xsl:choose>
<xsl:when test="capacityAvailability/highSpeedNotLessThan='true'">
<value>Yes</value>
<Characteristic>
<name><xsl:value-of select="concat(type,' ',capacityAvailability/featureType,' ','High Speed Tiers (greater or equal to ',capacityAvailability/capacity,capacityAvailability/unitOfMeasure,')')"/></name>
</Characteristic>
<Type>abcd</Type>
</xsl:when>
<xsl:when test="capacityAvailability/highSpeedNotLessThan='false'">
<value>No</value>
<Characteristic>
<name><xsl:value-of select="concat(type,' ',capacityAvailability/featureType,' ','High Speed Tiers (greater or equal to ',capacityAvailability/capacity,capacityAvailability/unitOfMeasure,')')"/></name>
</Characteristic>
<Type>abcd</Type>
</xsl:when>
</xsl:choose>
</DescribedBy>
</xsl:template>

</xsl:stylesheet>

请在此处查看它的工作情况:https://xsltfiddle.liberty-development.net/bEJbVrz

请注意,由于True和False情况下输出中的Characteristic和Type是相同的,所以您可以将它们从when条件中去掉,并将它们用于这两种情况,但我使用的方法与编写伪代码的方法相同。

相关内容

  • 没有找到相关文章

最新更新