Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 2nd, 2007, 12:13 AM
Registered User
 
Join Date: Jun 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default changing attribute value in MS word

Hi

I have the xml file with some attribute value. When i open my xml file in MS word 2003,the only text element is displayed in the word.
when i change the text element and save as data element only in word. After saving the xml changes take effect in xml. But my problem is how can i display the attribute value in word and also important is when i change the attribute value and save the xml then it must take the effect in saved xml.

Please suggest anybody to some xslt code to solve this problem.

Thanks and Regards
Sandeep s


 
Old June 2nd, 2007, 03:24 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

For some reason you don't seem to be able to do this in Word 2003. You can select an element, right-click and choose Attributes... but it doesn't actually save the edited value. I haven't tried it on a document that has an associated schema though, perhaps that would help.


--

Joe (Microsoft MVP - XML)
 
Old June 2nd, 2007, 02:15 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

A Word expert has explained how this is done. You do what I said before about opening the attributes dialogue box, then change the value, then click "Modify", this will save the change after you OK out.
Coincidentally this question arose at work the other day, I'm glad you reminded me to look into it again :)

--

Joe (Microsoft MVP - XML)
 
Old June 4th, 2007, 07:14 AM
Registered User
 
Join Date: Jun 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Joe. It is working fine.

But by problem is,

XML file(example.xml).

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<AAA >
          <BBB>sandeep </BBB>
          <ddd text="bangalore"></ddd>
      </AAA>

</document>

And XSl file(example.xsl)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ns1="urn:hl7-org:v3" xmlns:ns2="http://www.w3.org/2001/XMLSchema-instance">
  <xsl:output method="xml" encoding="UTF-8" standalone="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" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ns1="urn:hl7-org:v3" xmlns:ns2="http://www.w3.org/2001/XMLSchema-instance" w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no" xml:space="preserve">
        <w:fonts>
        <w:defaultFonts w:ascii="Times New Roman" w:fareast="Times New Roman" w:h-ansi="Times New Roman" w:cs="Times New Roman" />
      </w:fonts>
      <w:styles>
        <w:versionOfBuiltInStylenames w:val="4" />
        <w:latentStyles w:defLockedState="off" w:latentStyleCount="156" />
        <w:style w:type="paragraph" w:default="on" w:styleId="Normal">
          <w:name w:val="Normal" />
          <w:rPr>
            <wx:font wx:val="Times New Roman" />
            <w:sz w:val="24" />
            <w:sz-cs w:val="24" />
            <w:lang w:val="EN-US" w:fareast="EN-US" w:bidi="AR-SA" />
          </w:rPr>
        </w:style>
        <w:style w:type="character" w:default="on" w:styleId="DefaultParagraphFont">
          <w:name w:val="Default Paragraph Font" />
          <w:semiHidden />
        </w:style>
        <w:style w:type="table" w:default="on" w:styleId="TableNormal">
          <w:name w:val="Normal Table" />
          <wx:uiName wx:val="Table Normal" />
          <w:semiHidden />
          <w:rPr>
            <wx:font wx:val="Times New Roman" />
          </w:rPr>
          <w:tblPr>
            <w:tblInd w:w="0" w:type="dxa" />
            <w:tblCellMar>
              <w:top w:w="0" w:type="dxa" />
              <w:left w:w="108" w:type="dxa" />
              <w:bottom w:w="0" w:type="dxa" />
              <w:right w:w="108" w:type="dxa" />
            </w:tblCellMar>
          </w:tblPr>
        </w:style>
        <w:style w:type="list" w:default="on" w:styleId="NoList">
          <w:name w:val="No List" />
          <w:semiHidden />
        </w:style>
      </w:styles>
      <w:docPr>
        <w:view w:val="web" />
        <w:zoom w:percent="100" />
        <w:attachedTemplate w:val="" />
        <w:defaultTabStop w:val="720" />
        <w:characterSpacingControl w:val="DontCompress" />
        <w:validateAgainstSchema />
        <w:saveInvalidXML w:val="off" />
        <w:ignoreMixedContent />
        <w:alwaysShowPlaceholderText w:val="off" />
        <w:compat />
        <w:showXMLTags w:val="off" />
      </w:docPr>
      <w:body>
        <wx:sect>
          <xsl:apply-templates select="ns1:document" />
          <w:sectPr>
            <w:pgSz w:w="12240" w:h="15840" />
            <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="720" w:footer="720" w:gutter="0" />
            <w:cols w:space="720" />
            <w:docGrid w:line-pitch="360" />
          </w:sectPr>
        </wx:sect>
      </w:body>
      <o:CustomDocumentProperties>
        <o:processingInstructions dt:dt="string"> <xsl:for-each select="processing-instruction()"><xsl:text>&lt;?</xsl:text><xsl:value-of select="name()" /><xsl:text> </xsl:text><xsl:value-of select="." /><xsl:text>?&gt;</xsl:text></xsl:for-each></o:processingInstructions>
      </o:CustomDocumentProperties>
    </w:wordDocument>
  </xsl:template>
  <xsl:template match="/ns1:document">
    <ns1:document>
      <xsl:for-each select="@ns1:*|@*[namespace-uri()='']">
        <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
          <xsl:value-of select="." />
        </xsl:attribute>
      </xsl:for-each>
      <w:p />
      <xsl:apply-templates select="ns1:AAA" />
      <w:p />
    </ns1:document>
  </xsl:template>
  <xsl:template match="/ns1:document/ns1:AAA">
    <ns1:AAA>
      <xsl:for-each select="@ns1:*|@*[namespace-uri()='']">
        <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
          <xsl:value-of select="." />
        </xsl:attribute>
      </xsl:for-each>
      <w:p>
        <w:pPr>
          <w:ind w:left="360" />
        </w:pPr>
      </w:p>
      <xsl:apply-templates select="ns1:ddd|ns1:BBB" />
      <w:p>
        <w:pPr>
          <w:ind w:left="360" />
        </w:pPr>
      </w:p>
    </ns1:AAA>
  </xsl:template>
  <xsl:template match="/ns1:document/ns1:AAA/ns1:BBB">
    <ns1:BBB>
      <xsl:for-each select="@ns1:*|@*[namespace-uri()='']">
        <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
          <xsl:value-of select="." />
        </xsl:attribute>
      </xsl:for-each>
      <w:p>
        <w:pPr>
          <w:ind w:left="720" />
        </w:pPr>
        <w:r> <w:t><xsl:value-of select="." /></w:t></w:r>
      </w:p>
    </ns1:BBB>
  </xsl:template>
  <xsl:template match="/ns1:document/ns1:AAA/ns1:ddd">
    <ns1:ddd text="bangalore">
      <xsl:for-each select="@ns1:*|@*[namespace-uri()='']">
        <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
          <xsl:value-of select="." />
        </xsl:attribute>
      </xsl:for-each>
      <w:p>
        <w:pPr>
          <w:ind w:left="720" />
        </w:pPr>
        <w:r>
          <w:t>
            <xsl:value-of select="." />
          </w:t>
        </w:r>
      </w:p>
    </ns1:ddd>
  </xsl:template>
</xsl:stylesheet>


I have these two file.I will open the example.xml in word 2003 it will be opened in word. Afterwards I will browse the example.xsl file from its location. Then I will see the text element i.e., 'sandeep' but I can't see the attribute value 'bangalore' in word.

  It is must to see in the word and also when i change the attribute value it will take the effect in after saving.

Please provide some code in this XSLT. or any other way. I will try lot on this problem. So please help me

Thanks and Regards
Sandeep. S



 
Old June 7th, 2007, 05:54 AM
Authorized User
 
Join Date: Apr 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think it is because you are using
<xsl:value-of select="." />
this will fetch only node value if your for-each is matched
with node,try using @text.

Regards
Pradeep






Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Ms Access report to MS Word doc kite Access 1 October 22nd, 2007 01:45 AM
MS Access ----> MS Word anukagni Access 1 August 30th, 2006 02:15 AM
Changing the attribute values in XSLT NEO1976 XSLT 5 May 23rd, 2006 03:53 AM
changing the value of attribute name stone XSLT 1 October 21st, 2005 06:35 AM
changing attribute value in xslt rameshnarayan XSLT 1 August 16th, 2005 08:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.