2012-01-25 3 views
0

XML 값을 사용하여 단어 스키마 ml의 특성 값을 변경하려고합니다.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> 

어떤 이유를 들어

... 
$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(); 
} 

PHP, 그것은 생성 된 문서의 이미지를 변경하지 않는 것. Word 문서 템플릿의 기존 이미지를 사용하고 있습니다.

감사 존

+0

원하는 속성 값을 얻지 못하면 John,''괜찮습니다. 그런 다음 경로가 작동하지 않아 올바른 경로를 돕기 위해 코드 예제가있는 XSLT에서 XML 및 컨텍스트 노드 샘플을 표시해야합니다. –

+0

감사합니다 마틴, 더 많은 정보를 가지고 제 질문을 업데이트했습니다. 내가 템플릿으로 사용하고있는 Word 문서와 관련이 있는지 또는 다른 것을 놓치고 있는지 확실하지 않습니다. 다시 한번 감사드립니다. – johnnycanehdian

+0

@ johnnycanehdian : XSLT 프로세서에 문제가 있습니다. 색슨 6.5.4 당신의 변환을 적용 할 때, 나는 소지품. –

답변

1

난 변환을 시도하고 그 결과 (즉 DESCR 속성 값이 Assessment.xml에서 가져온) 좋았다. addFromString 메서드가 성공적입니까? 결과를 나타내는 bool 값을 반환합니다. word/document.xml이 이미 아카이브에 있으므로 덮어 쓸 수 없으므로 실패 할 수 있습니까? 즉, 먼저 삭제해야합니다.

+0

응답 해 주셔서 감사합니다. 다른 모든 값이 올바르게 업데이트되기 때문에 addFromString이 작동한다고 가정합니다. 대체되지 않는 이미지 만 있습니다. 템플릿에서/document.xml이라는 단어를 삭제하려고했지만 동일한 결과가있었습니다. – johnnycanehdian

0

좋아, 그럼 aparently 위의 내 코드가 잘 작동합니다. 문제는 Word 2007 캐싱 이미지 때문입니다. 올바른 이미지가 들어갈 수 있도록/media 폴더에있는 파일을 업데이트 할 수 있지만 문서 자체를 볼 때 캐시 된 이미지는 계속 표시됩니다.

동일한 문제가있는 경우 보조 질문 인 here을 만들었습니다.

도움 주셔서 감사합니다.