将xml转换为xslt时,值不是映射

时间:2015-04-29 17:10:04

标签: xml xslt

您好我是新的xslt转换我试图使用xslt转换后续xml,但我没有在结果xml中获得title的值。

Input Xml: 

   <exam:orderReq>

                  <exam:item>

                    <exam:title>r</exam:title>

                    </exam:item>

              </exam:orderReq>

Xslt: 

     <?xml version="1.0"?>

        <xsl:stylesheet version="1.0" 

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  

xmlns:exam="http://www.jboss.org/bpel/examples" 

xmlns:prod="http://www.jboss.org/bpel/examples/product">

            <xsl:template match="/">

             <prod:productOrderReq>

        <prod:product xmlns:prod="http://www.jboss.org/bpel/examples/product">

             <xsl:for-each select="exam:orderReq">

             <prod:name><xsl:value-of select="exam:title"/></prod:name>

                 </xsl:for-each>

        </prod:product>

              </prod:productOrderReq>

            </xsl:template> 

        </xsl:stylesheet>

我得到了结果iin,我无法获得元素的值

<?xml version="1.0" encoding="UTF-8"?>

        <prod:productOrderReq 

xmlns:prod="http://www.jboss.org/bpel/examples/product" 

xmlns:exam="http://www.jboss.org/bpel/examples">

           <prod:product>

              <prod:name />

           </prod:product>

        </prod:productOrderReq>

1 个答案:

答案 0 :(得分:0)

I got the solution while writing xslt i missed the for each tag for the item as shown below.

Previous xslt:


xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  

xmlns:exam="http://www.jboss.org/bpel/examples" 

xmlns:prod="http://www.jboss.org/bpel/examples/product">

            <xsl:template match="/">

             <prod:productOrderReq>

        <prod:product xmlns:prod="http://www.jboss.org/bpel/examples/product">

             <xsl:for-each select="exam:orderReq">

             <prod:name><xsl:value-of select="exam:title"/></prod:name>

                 </xsl:for-each>

        </prod:product>

              </prod:productOrderReq>

            </xsl:template> 

        </xsl:stylesheet>


Modified xslt:

 <?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  

xmlns:exam="http://www.jboss.org/bpel/examples" 

xmlns:prod="http://www.jboss.org/bpel/examples/product">

    <xsl:template match="/">

     <prod:productOrderReq>

     <xsl:for-each select="exam:orderReq" 

xmlns:exam="http://www.jboss.org/bpel/examples">

<prod:product>

     <xsl:for-each select="exam:item">

     <prod:name><xsl:value-of select="exam:title"/></prod:name>

         </xsl:for-each>

</prod:product>

</xsl:for-each>

      </prod:productOrderReq>

    </xsl:template> 

</xsl:stylesheet>