java—如何将值从xmlMap到xslt

falq053o  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(342)

我正在尝试将数据从xml填充到xslt,但无法做到这一点,因为我不知道xslt和xpath。尽管我尽了最大努力(使用concat()方法),但还是做不到。你能帮我做下面的Map吗----
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>

试图达到以下目标one:--

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

条件到map:---

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"
            }
}

这就是我所尝试过的far:--

<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>
oyxsuwqo

oyxsuwqo1#

下面是如何使用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情况是相同的,所以您可以将它们从when条件中去掉,并将它们用于这两种情况,但我使用与编写伪代码相同的方法。

相关问题