Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将值从xml映射到XSLT_Java_Xml_Xslt_Xpath - Fatal编程技术网

Java 如何将值从xml映射到XSLT

Java 如何将值从xml映射到XSLT,java,xml,xslt,xpath,Java,Xml,Xslt,Xpath,我正在尝试将数据从xml填充到xslt,但无法做到这一点,因为我不知道xslt和xpath。你能帮我做下面的地图吗---- Xml:-----(一段代码) 这就是我迄今为止所尝试的:-- 对 不 abcd 以下是使用XSLT的方法 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transf

我正在尝试将数据从xml填充到xslt,但无法做到这一点,因为我不知道xslt和xpath。你能帮我做下面的地图吗----

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

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


对
不
abcd

以下是使用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>

对
abcd
不
abcd
看到它在这里工作:


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

如果您对XSLT和XPath一无所知,那么您应该了解这一点并进行一些教程。“从XML到XSLT”到底是什么意思?在您的代码片段中,这是一种什么样的语言?它既不是Java也不是XSLT。请尽量弄清楚你的实际问题是什么。“你的问题很让人困惑。@vanje使用concat()方法尝试了很多,但都没有成功。所以请求帮助是的,你已经提到了。但这并不能让事情变得更清楚。你根本没有回答我的问题。也许你应该阅读和阅读。现在还完全不清楚您想要完成什么。@priyranjan所以请发布失败的XSLT,而不是一些不可理解的伪代码@陀螺仪无齿轮..到目前为止我已经试过了,现在补充。谢谢。这真的帮了我很大的忙。
<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>
<?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>