Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 11-03-2009, 10:30 PM   PM User | #1
senglory
New Coder

 
Join Date: Jul 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
senglory is an unknown quantity at this point
Question Why do I get <w:p> w/o attributes?

XML:

Code:
<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:smartTag w:uri="http://schemas.openxmlformats.org/2006/smarttags" w:element="livetechdocs"><w:smartTagPr><w:attr w:name="remap"></w:attr></w:smartTagPr></w:smartTag>
            <w:pPr>
                <w:tabs>
                    <w:tab w:val="left" w:pos="8186"></w:tab>
                </w:tabs>
                <w:rPr>
                    <w:sz w:val="14"></w:sz>
                    <w:szCs w:val="14"></w:szCs>
                </w:rPr>
            </w:pPr>
        </w:p>
    </w:body>
</w:document>
XSL:

Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
        xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
        xmlns:o="urn:schemas-microsoft-com:office:office"
        xmlns:v="urn:schemas-microsoft-com:vml"
        xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
        xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
        xmlns:w10="urn:schemas-microsoft-com:office:word"
        xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
        xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
        xmlns:rs="http://schemas.openxmlformats.org/package/2006/relationships"
        version="1.0">

    <xsl:output method="html" encoding="utf-8" omit-xml-declaration="no" indent="yes"/>


    <!-- http://stackoverflow.com/questions/1312210/conditional-auto-increment-in-xsl -->
    <xsl:template match="w:p[count(ancestor::w:tbl)=0]|w:tbl[count(ancestor::w:tbl)=0]|w:footnote[count(ancestor::w:tbl)=0]|w:endnote[count(ancestor::w:tbl)=0]|w:docPart[count(ancestor::w:tbl)=0]">

        <xsl:copy>
            <w:smartTag w:uri="http://schemas.openxmlformats.org/2006/smarttags" w:element="livetechdocs">
                <w:smartTagPr>
                    <xsl:element name="w:attr">
                        <xsl:attribute name="w:name">remap</xsl:attribute>
                    </xsl:element>
                </w:smartTagPr>
            </w:smartTag>

            <xsl:apply-templates/>

        </xsl:copy>

    </xsl:template>

   
    <xsl:template match="node() | text()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

Why do I get <w:p> w/o attributes?

Thanks for advise.
senglory is offline   Reply With Quote
Old 11-03-2009, 11:16 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 1,368
Thanks: 3
Thanked 181 Times in 172 Posts
rnd me will become famous soon enoughrnd me will become famous soon enough
1. <w: p> has no attribs in the example source.

2. you never copy the attribs, just nodes and text...

try copy-of instead.

also, just an aside:
since 0 is false,
Code:
w:footnote[count(ancestor::w:tbl)=0]
is the same as
Code:
w:footnote[count(ancestor::w:tbl)]
which, since a node is true, is likely the same as just:
Code:
w:footnote[ancestor::w:tb]

Last edited by rnd me; 11-03-2009 at 11:19 PM..
rnd me is offline   Reply With Quote
Old 11-03-2009, 11:32 PM   PM User | #3
senglory
New Coder

 
Join Date: Jul 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
senglory is an unknown quantity at this point
sorry, the original XML is

Quote:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns="urn:schemas-microsoft-comfficeffice" 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-comffice:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
<w:body>
<w w:rsidR="000E17AA" w:rsidRDefault="000E17AA">
<wPr>
<w:tabs>
<w:tab w:val="left" wos="8186"/>
</w:tabs>
<w:rPr>
<w:sz w:val="14"/>
<w:szCs w:val="14"/>
</w:rPr>
</wPr>
</w>
</w:body>
</w:document>
senglory is offline   Reply With Quote
Old 11-03-2009, 11:35 PM   PM User | #4
senglory
New Coder

 
Join Date: Jul 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
senglory is an unknown quantity at this point
Question

Quote:
Originally Posted by rnd me View Post
1. <w: p> has no attribs in the example source.

2. you never copy the attribs, just nodes and text...

try copy-of instead.

also, just an aside:
since 0 is false,
Code:
w:footnote[count(ancestor::w:tbl)=0]
is the same as
Code:
w:footnote[count(ancestor::w:tbl)]
which, since a node is true, is likely the same as just:
Code:
w:footnote[ancestor::w:tb]

btw, if I want to select nodes that has NO w:tbl as their ancestors what should i write?
senglory is offline   Reply With Quote
Old 11-04-2009, 09:35 PM   PM User | #5
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 1,368
Thanks: 3
Thanked 181 Times in 172 Posts
rnd me will become famous soon enoughrnd me will become famous soon enough
Quote:
Originally Posted by senglory View Post
btw, if I want to select nodes that has NO w:tbl as their ancestors what should i write?
yes, i made a mistake in the exmaple i posted, flipping the conditional halfway, sorry about that.

Code:
<copy-of select="w:p[not(ancestor::w:tbl)]" />
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
senglory (11-18-2009)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:09 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.