xsl-list
[Top] [All Lists]

Automatically copying an element's attributes and their values

2003-09-07 13:11:06

I would like to pass through attributes and their
values without having to a) test to see if the
attribute has a value specified, and b) explicitly
output the value.

This is the code I'm currently using:

        <xsl:template match="ns0:para"
mode="blockindent">
                <xsl:choose>
                        <xsl:when test="@id">
                                <ns0:para
id="{(_at_)id}">
                                        <w:p>
        
<w:pPr>
        
<w:pStyle w:val="Blockindent"/>
        
</w:pPr>
        
<xsl:apply-templates mode="para"/>
                                        </w:p>
                                </ns0:para>
                        </xsl:when>
                        <xsl:otherwise>
                                <ns0:para>
                                        <w:p>
        
<w:pPr>
        
<w:pStyle w:val="Blockindent"/>
        
</w:pPr>
        
<xsl:apply-templates mode="para"/>
                                        </w:p>
                                </ns0:para>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>


I tried using the code submitted by Mike Brown in
Dave Pawson's FAQ:

<ns0:para>
        <xsl:for-each select="@*">
        <xsl:attribute name="name()">
                        <xsl:value-of select="."/>
                </xsl:attribute>
    </xsl:for-each>
... Remainder of template

But using MSXML 3.0 in XMLSpy and Xselerator I got
an error "This name may not contain the '('
character: name-->(<--); if I use the default XSLT
processor in XMLSpy I don't get an error, but the
attributes do not appear in my result file. The
final transform will end up being performed using
MSXML.

It should also be noted that my source instance
does not contain namespace prefixes (i.e.
<para>asd;fljk adsflkjsda f</para>
<para id="1234">adlfkj</para>)

Thanks in advance,

Mary



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list