0

I convert Attributes to a table, but I dont know which attributes will be set, so I got following solution:

                <simpletable  spectitle="Chapter Attribute">
                    <sthead>
                        <stentry>Name</stentry>
                        <stentry>Wert</stentry>
                    </sthead>
                    <xsl:apply-templates select="@*"/>
                    <xsl:apply-templates select="Head/@*"/>
                </simpletable>

<!-- ********************* Chapter Attribute -> simpleTable....strow ************************************************************************************** -->
<xsl:template match="Chapter/@*|Head/@*">
    <xsl:choose>
        <xsl:when test="string(.)">
            <strow>
                <stentry>
                    <xsl:value-of select="local-name(.)"/>
                </stentry>
                <stentry>
                    <xsl:value-of select="."/>
                </stentry>
            </strow>
        </xsl:when>
    </xsl:choose>
</xsl:template>

Here is my XML to process:

<Chapter title="Information" termpool="" nodeid="DE-123" xmltag="Chapter" 
 status="" id="" language="" version="">
<Head UniqueID="DE-234" xmlns:axf="http://www.antennahouse.com/names
         /XSL/Extensions">Information</Head>

This is the result

<strow>
    <stentry>title</stentry>
    <stentry>Information</stentry>
</strow>
<strow>
    <stentry>nodeid</stentry>
    <stentry>DE-123</stentry>
</strow>
<strow>
    <stentry>xmltag</stentry>
    <stentry>Chapter</stentry>
</strow>
<strow>
    <stentry>UniqueID</stentry>
    <stentry>DE-234</stentry>
</strow>

For the << Chapter >> it works fine, but for << Head >> it doesnt recognise xmlns:axf (or that xmlns:axf has a vaule set)

Hope someone got a hint for me, how to access xmlns:axf with @* Thanks Jochen

1 Answer 1

1

In the XDM data model used by XPath, namespaces and attributes are completely different things. The attribute axis @* gives you the attributes, for the namespaces you need the namespace axis namespace::*.

Note that this will give you all the namespaces that are in scope for an element, not only those that were declared on that element. If you really want the namespaces that are present on an element and that are not present on the parent element, the logic will depend on which version of XSLT you are using, which you haven't told us.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your answer, but it get errors. I use Version 2.0. I tried
Thank you for your answer, but it get errors. I use Version 2.0. I tried <xsl:apply-templates select="Head/namespace::@*"/> or <xsl:apply-templates select="Head/xmlns::@*"/> which both failed on execution. <xsl:template match="Head/namespace::@*"> wasnt acceptet. I guess I understood something wrong.
My xmlspy says about the xpath, that the namespace xmlns is undefined and really, its not declared in tge top of my xml, Perhapst this causes the problem: <?xml version="1.0" encoding="utf-8"?> <fctdcl ...some normal attributes ...>
I told you to use namespace::*, so why are you trying to use xmlns::@* and namespace::@*? Also, please don't just type in code you find in an SO answer without first going to a reference book so you understand what it actually means.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.