Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
XML->;XSLT->;每个字不循环_Xml_Xslt - Fatal编程技术网

XML->;XSLT->;每个字不循环

XML->;XSLT->;每个字不循环,xml,xslt,Xml,Xslt,我已经将我的SQL客户端从MySQL查询浏览器更新到MySQL工作台。 升级后,我的XML格式发生了变化,XSLT不再工作。它将只显示第一项 这里是XML和XSLT的简化版本,它的输出发送到MySQL数据库 XML 期望输出 <w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"> <w:body> <w:p> <w:r>

我已经将我的SQL客户端从MySQL查询浏览器更新到MySQL工作台。 升级后,我的XML格式发生了变化,XSLT不再工作。它将只显示第一项

这里是XML和XSLT的简化版本,它的输出发送到MySQL数据库

XML

期望输出

<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
  <w:body>
    <w:p>
      <w:r>
        <w:t>1- Some vulnerability</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>2- Some Other Vulnerability</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>3- Yet another vulnerability</w:t>
      </w:r>
    </w:p>
  </w:body>
</w:wordDocument>

1-一些脆弱性
2-其他一些漏洞
3-另一个漏洞

谢谢。

这应该可以满足您的要求:

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

    <xsl:processing-instruction name="mso-application">
      <xsl:text>progid="Word.Document"</xsl:text>
    </xsl:processing-instruction>
    <w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
      <w:body>
        <xsl:for-each select="ROW">
          <w:p>
            <w:r>
              <w:t>
                <xsl:value-of select="concat(count(preceding-sibling::ROW)+1,'- ',Nom)"/>
              </w:t>
            </w:r>
          </w:p>
        </xsl:for-each>
      </w:body>
    </w:wordDocument>
  </xsl:template>
</xsl:stylesheet>

progid=“Word.Document”
“更多XSLT”解决方案是:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/DATA">

    <xsl:processing-instruction name="mso-application">
      <xsl:text>progid="Word.Document"</xsl:text>
    </xsl:processing-instruction>
    <w:wordDocument>
      <w:body>
        <xsl:apply-templates select="ROW"/>
      </w:body>
    </w:wordDocument>
  </xsl:template>

  <xsl:template match="ROW">
    <w:p>
      <w:r>
        <w:t>
          <xsl:value-of select="concat(count(preceding-sibling::ROW)+1,'- ',Nom)"/>
        </w:t>
      </w:r>
    </w:p>
  </xsl:template>
</xsl:stylesheet>

progid=“Word.Document”
两者的输出均为:

<?xml version="1.0" encoding="utf-8"?><?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
  <w:body>
    <w:p>
      <w:r>
        <w:t>1- Some vulnerability</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>2- Some Other Vulnerability</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>3- Yet another vulnerability</w:t>
      </w:r>
    </w:p>
  </w:body>
</w:wordDocument>

1-一些脆弱性
2-其他一些漏洞
3-另一个漏洞

progid=“Word.Document”

感谢您的快速回复。使用这两个XSLT可以得到与我完全相同的结果,并在
Nom
前面加上一个
1-
。似乎“循环”由于某种原因仍然不起作用……这很奇怪。使用Saxon、Xalan、xsltproc或Firefox的内置XSLT处理器,这两种方法的结果基本相同。你在用什么?好的,有人更正了我的输入XML。似乎是
中的空格造成了问题。我更改了
的名称,它现在正在处理。我正在使用以下使用irb和nokogiri的linux脚本。irb-看起来非常复杂的宝石。Nokogiri在后台使用libxslt,您可以直接使用它,如
xsltproc NessusTable.xslt MyXML.xml
。它也可用于Windows:。还有Saxon和Xalan,它们都是跨平台的,还有微软自己的XSLT处理器(显然不是跨平台的)。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/DATA">

    <xsl:processing-instruction name="mso-application">
      <xsl:text>progid="Word.Document"</xsl:text>
    </xsl:processing-instruction>
    <w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
      <w:body>
        <xsl:for-each select="ROW">
          <w:p>
            <w:r>
              <w:t>
                <xsl:value-of select="concat(count(preceding-sibling::ROW)+1,'- ',Nom)"/>
              </w:t>
            </w:r>
          </w:p>
        </xsl:for-each>
      </w:body>
    </w:wordDocument>
  </xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/DATA">

    <xsl:processing-instruction name="mso-application">
      <xsl:text>progid="Word.Document"</xsl:text>
    </xsl:processing-instruction>
    <w:wordDocument>
      <w:body>
        <xsl:apply-templates select="ROW"/>
      </w:body>
    </w:wordDocument>
  </xsl:template>

  <xsl:template match="ROW">
    <w:p>
      <w:r>
        <w:t>
          <xsl:value-of select="concat(count(preceding-sibling::ROW)+1,'- ',Nom)"/>
        </w:t>
      </w:r>
    </w:p>
  </xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?><?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
  <w:body>
    <w:p>
      <w:r>
        <w:t>1- Some vulnerability</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>2- Some Other Vulnerability</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>3- Yet another vulnerability</w:t>
      </w:r>
    </w:p>
  </w:body>
</w:wordDocument>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/DATA">

    <xsl:processing-instruction name="mso-application">
      <xsl:text>progid="Word.Document"</xsl:text>
    </xsl:processing-instruction>
    <w:wordDocument
      xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">

      <w:body>
        <xsl:for-each select="//ROW">
          <xsl:variable name="pos" select="position()"/>
          <w:p>
            <w:r>
              <w:t>
              <xsl:value-of select="concat($pos,'-')"/>
              <xsl:value-of select="Nom"/>
              </w:t>
            </w:r>
          </w:p>
        </xsl:for-each>
      </w:body>
    </w:wordDocument>

  </xsl:template>
</xsl:stylesheet>