2012-01-25 13 views
0

XML値を使用して単語スキーマの属性の値を変更しようとしています。WordML属性の更新インライン

... 
<wp:docPr id="3" name="Picture 3" descr="http://pathtoimage.png"/> 
... 
私はこのようなXML値とDESCR値を変更したい

...

... 
<wp:docPr id="3" name="Picture 3" descr="<xsl:value-of select='Assessment/Scorecard/Graph0' />" /> 
... 

しかし、これは動作しません。インラインのxsl値が好きではありません。私もこれを試しました...

... 
<wp:docPr id="3" name="Picture 3" descr="{Assessment/Scorecard/Graph0}" /> 
... 

これはエラーではありませんが、動作しません。

XML値でインラインの値を変更する方法はありますか。

詳細を更新中...

XML

<?xml version="1.0" encoding="utf-8"?> 
<Assessment> 
<Title> 
    <CompanyName>Company Name</CompanyName> 
    <ReportDate>January 25th, 2012</ReportDate> 
    <Address> 
     <Line>Line 1</Line> 
    </Address> 
    <Address> 
     <Line>Line 2</Line> 
    </Address> 
    <Address> 
     <Line>Line 3</Line> 
    </Address> 
    <Address> 
     <Line>Line 4</Line> 
    </Address> 
</Title> 

<Scorecard> 
    <SuppliesAndServiceLogistics>5.2</SuppliesAndServiceLogistics> 
    <PrintingHardwareUsage>5.3</PrintingHardwareUsage> 
    <TechnologyReliabilityAndUserProductivity>4.2</TechnologyReliabilityAndUserProductivity> 
    <EnvironmentalImpact>3.0</EnvironmentalImpact> 
    <Expense>1.8</Expense> 
    <Graph0>http://path_to_image/Graph0.png</Graph0> 
    <Savings>$43,526</Savings> 
</Scorecard> 
... 
</Assessment> 

XSLT

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

<xsl:template match="/"> 

<w:document 
    xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:o="urn:schemas-microsoft-com:office:office" 
    xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 
    xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" 
    xmlns:v="urn:schemas-microsoft-com:vml" 
    xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" 
    xmlns:w10="urn:schemas-microsoft-com:office:word" 
    xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" 
    xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"> 

    <w:body> 
    ... 

    <w:p w:rsidR="0057097D" w:rsidRDefault="0057097D"> 
     <w:pPr> 
     <w:jc w:val="center"/> 
     <w:rPr> 
      <w:rFonts w:ascii="Arial" w:eastAsia="Times New Roman" w:hAnsi="Arial" w:cs="Arial"/> 
     </w:rPr> 
     </w:pPr> 
     <w:r> 
     <w:rPr> 
      <w:rFonts w:ascii="Arial" w:eastAsia="Times New Roman" w:hAnsi="Arial" w:cs="Arial"/> 
      <w:noProof/> 
     </w:rPr> 
     <w:drawing> 
      <wp:inline distT="0" distB="0" distL="0" distR="0"> 
      <wp:extent cx="5709285" cy="1524000"/> 
      <wp:effectExtent l="19050" t="0" r="5715" b="0"/> 
      <wp:docPr id="3" name="Picture 3" descr="{Assessment/Scorecard/Graph0}"/> 
      <wp:cNvGraphicFramePr> 
       <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/> 
      </wp:cNvGraphicFramePr> 
      <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> 
       <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
       <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
        <pic:nvPicPr> 
        <pic:cNvPr id="0" name="Picture 3" descr="{Assessment/Scorecard/Graph0}"/> 
        <pic:cNvPicPr> 
         <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/> 
        </pic:cNvPicPr> 
        </pic:nvPicPr> 
        <pic:blipFill> 
        <a:blip r:embed="rId9" r:link="rId10" cstate="print"/> 
        <a:srcRect/> 
        <a:stretch> 
         <a:fillRect/> 
        </a:stretch> 
        </pic:blipFill> 
        <pic:spPr bwMode="auto"> 
        <a:xfrm> 
         <a:off x="0" y="0"/> 
         <a:ext cx="5709285" cy="1524000"/> 
        </a:xfrm> 
        <a:prstGeom prst="rect"> 
         <a:avLst/> 
        </a:prstGeom> 
        <a:noFill/> 
        <a:ln w="9525"> 
         <a:noFill/> 
         <a:miter lim="800000"/> 
         <a:headEnd/> 
         <a:tailEnd/> 
        </a:ln> 
        </pic:spPr> 
       </pic:pic> 
       </a:graphicData> 
      </a:graphic> 
      </wp:inline> 
     </w:drawing> 
     </w:r> 
    </w:p> 

    ... 

    </w:body> 

</w:document> 

何らかの理由によりPHP

... 
$xmlDataFile = ("Assessment.xml"); 
$xsltFile = ("Assessment.xslt"); 
$sourceTemplate = ("AssessmentTemplate.docx"); 
$outputDocument = ("Assessment.docx"); 

//Load the xml data and xslt and perform the transformation. 
$xmlDocument = new DOMDocument(); 
$xmlDocument->load($xmlDataFile); 

$xsltDocument = new DOMDocument(); 
$xsltDocument->load($xsltFile); 

$xsltProcessor = new XSLTProcessor(); 
$xsltProcessor->importStylesheet($xsltDocument); 

//After the transformation, $newContentNew contains 
//the XML data in the Open XML Wordprocessing format. 
$newContent = $xsltProcessor->transformToXML($xmlDocument); 

//Copy the Word 2007 template document to the output file. 
if (copy($sourceTemplate, $outputDocument)) { 
    //Open XML files are packaged following the Open Packaging 
    //Conventions and can be treated as zip files when 
    //accessing their content. 
    $zipArchive = new ZipArchive(); 
    $zipArchive->open($outputDocument); 

    //Replace the content with the new content created above. 
    //In the Open XML Wordprocessing format content is stored 
    //in the document.xml file located in the word directory. 
    $zipArchive->addFromString("word/document.xml", $newContent); 
    $zipArchive->close(); 
} 

、それが生成されたドキュメント内の画像を変更していません。 Word文書テンプレートの既存の画像を使用しています。

おかげジョン

+0

希望の属性値を取得しないと、 ''は問題ありません。 XMLとXMLのサンプルをXSLTに表示する必要がある正しいパスを手助けするために、パスが機能しないようにしてください。 –

+0

Martinさん、ありがとうございました。私がテンプレートとして使用しているWord文書と関係があるかどうか、または別のものがない場合はわかりません。再度、感謝します。 – johnnycanehdian

+0

@ johnnycanehdian:XSLTプロセッサに問題があります。ザクセン6.5。4あなたの変換を適用すると、 'もの。 –

答えて

1

私は変換を試み、その結果(即ちDESCR属性の値をAssessment.xmlから取られた)良かったです。 addFromStringメソッドが成功していますか?結果を示すブール値を返します。 word/document.xmlが既にアーカイブに存在し、上書きできない(つまり、最初に削除する必要がある)ため、失敗する可能性はありますか?

+0

お返事ありがとうございます。私は他のすべての値が正しく更新されているので、addFromStringが動作すると仮定しています。それは置き換えられない画像だけです。私はテンプレートから/ document.xmlという単語を削除しようとしましたが、同じ結果がありました。 – johnnycanehdian

0

上記のコードでは、上のコードはうまくいきます。問題は、Word 2007のキャッシュイメージにあります。正しい画像がそこにあるように単語/メディアフォルダ内のファイルを更新できますが、文書自体を表示すると、キャッシュされた画像はまだ表示されています。

同じ問題が発生した場合は、フォローアップの質問hereを作成しました。

ありがとうございました!

関連する問題