2012-11-29 3 views
0

SQL 클라이언트를 MySQL Query Browser에서 MySQL Workbench로 업데이트했습니다. 업그레이드를 통해 XML 형식이 변경되고 XSLT가 더 이상 작동하지 않습니다. 첫 번째 항목 만 표시됩니다.XML -> XSLT -> for for each not looping

여기 XML과 XSLT의 단순화 된 버전입니다. Nessus 출력이 MySQL 데이터베이스로 전송됩니다.

XML 그때 Word 문서에 두 가지를 병합 스크립트에서 그 구문 분석

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

    <ROW> 
     <Niveau>Haute</Niveau> 
     <Nom>Some vulnerability</Nom> 
     <Solution>Some Solution</Solution> 
     <cve>CVE-2006-1234, CVE-2006-5615</cve> 
     <bid>11263, 11291</bid> 
     <Number>5</Number> 
    </ROW> 

    <ROW> 
     <Niveau>Haute</Niveau> 
     <Nom>Some Other Vulnerability</Nom> 
     <Solution>Apply the security patch.</Solution> 
     <cve>CVE-2006-1742, CVE-2006-1743</cve> 
     <bid>20584, 20585</bid> 
     <Number>23</Number> 
    </ROW> 

    <ROW> 
     <Niveau>Moyenne</Niveau> 
     <Nom>Yet another vulnerability</Nom> 
     <Solution>Do this and that</Solution> 
     <cve></cve> 
     <bid></bid>     
     <Number>2</Number> 
    </ROW> 


</DATA> 

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="/"> 

    <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="DATA/ROW"> 
      <w:p> 
      <w:r> 
       <w:t><xsl:value-of select="Nom"/></w:t> 
      </w:r> 
      </w:p> 
     </xsl:for-each> 
     </w:body> 
    </w:wordDocument> 

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

. 그것은 내가 가진 것처럼 많은 테이블을 생성하는 데 사용됩니다. 하지만 지금은 첫 번째 줄만 얻습니다. 나는 그것이 <xsl:template match="/"> 또는 <xsl:for-each select="DATA/ROW">과 관련이 있다고 확신하지만 올바른 조합을 찾을 수없는 것 같습니다.

Nom처럼 순차 번호를 추가하는 방법을 알려줄 수 있다면 1- Nom 나는 매우 행복한 캠프가 될 것입니다.

<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"> 
    <w:body> 
    <w:p> 
     <w:r> 
     <w:t>Some vulnerability</w:t> 
     </w:r> 
    </w:p> 
    </w:body> 
</w:wordDocument> 

원하는 출력

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

전류 출력 감사합니다.

답변

0

이것은 당신이 원하는 일을해야합니다

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

A "더 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> 

출력은 다음과 같습니다

<?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> 
+0

감사합니다 매우 빠른 답장을 위해. 이 두 XSLT를 사용하면 광산과 정확히 같은 결과를 얻고 'Nom'앞에 '1-'을 표시합니다. 어떤 이유로 든 "루프"가 여전히 작동하지 않는 것 같습니다. – Scoubidou

+0

그건 이상합니다. 둘 다 Saxon, Xalan, xsltproc 또는 Firefox의 내장 XSLT 프로세서를 사용하여 기본적으로 동일한 출력을 얻습니다. 뭐라구? –

+0

좋아, 누군가 내 입력 XML을 수정했습니다. '<영향을받은 수> '의 공간이 문제를 일으키고있는 것 같습니다. 나는 ''의 이름을 변경하고 처리합니다. irb와 nokogiri를 사용하는 다음 리눅스 스크립트를 사용하고 있습니다. irb -rrubygems << EOF "Nokogiri"가 필요합니다 # 원본 = Nokogiri :: XML (File.read ('$ XMLFILE')) 원본 = Nokogiri :: XML (File.read ('MyXML.xml')) XSLT = 노코 기리 :: XSLT는 (File.read가 ('NessusTable.xslt이')) 가 xslt.transform을두고 (소스) 종료 EOF 이이 질문의 외부에있는,하지만 당신은 무료 소프트웨어를 알고있는 경우 그 위해 할 수있는 Windows에서의 트릭을 알고 기뻤습니다! – Scoubidou

0
<?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>