[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT and XPath 2.0: finding unused namespace declarat

Subject: XSLT and XPath 2.0: finding unused namespace declarations
From: "Timothy M. Lebo" <tlebo@xxxxxxxxx>
Date: Fri, 10 Oct 2003 12:26:51 -0500
xpath newline
Hello,

As an exercise for adapting to the changes in XSLT and Xpath 2.0, I'm
trying to write a stylesheet to report all namespaces that are in scope
anywhere in the document, what their NCNames and expansions are, and the
status of their usage.

For Example, with an input document:
<root
  xmlns:first="first.com"
  xmlns:second="second.com"
  xmlns:third="third.com">

  <first:child xmlns:fourth="fourth.com">
    <second:grandchild xmlns:fifth="fifth.com/>
  </first:child>
</root>

The stylesheet would return something like:
Xml = w3.org/XML/98/namespace (unused)
first = first.com (used)
second = second.com (used)
third = third.com (unused)
fourth = fourth.com (unused)
fifth = fifth.com (unused)

I continue to run into problems with datatypes and sequences. What is
the best way to mold one's understanding of node sets to understand how
to manipulating sequences? It would seem to me if I had a set of
in-scope nodes and I knew the namespace being used, it is a matter of
set containment.

Here is the code, which I am very ashamed to distribute. It falls short
in many respects, including style. I would much prefer to expunge the
for loops.

Regards,

Timothy M. Lebo
Research Associate
Smart Information Flow Technologies

<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:value-of select="concat(base-uri(.),$newline)"/>
    <xsl:value-of select="concat('    declares: ',$newline,'
')"/>
    <xsl:value-of select="get-in-scope-namespaces(*[1])"/>
    <xsl:value-of select="concat($newline,'    usage    : ',$newline)"/>

    <xsl:for-each-group select="//*" group-by="namespace-uri()">
      <xsl:variable name="me" select="."/>
      <xsl:variable name="myNS"
select="get-namespace-from-QName(node-name($me))"/>
      <xsl:variable name="my_inScope_NS"
select="get-in-scope-namespaces(.)"/>
      <xsl:for-each select="get-in-scope-namespaces(.)">
        <xsl:sort select="."/>
        <xsl:if test="get-namespace-uri-for-prefix($me,.) = $myNS">
          <xsl:value-of select="concat('             ',.,' =
',get-namespace-uri-for-prefix($me,.))"/>
        </xsl:if>
      </xsl:for-each>
      <xsl:if test="some $x in $my_inScope_NS satisfies $x =
get-namespace-uri-for-prefix($me,$x)">
	<xsl:value-of select="concat('  (used)',$newline)"/>
      </xsl:if>
      <xsl:if test="every $x in $my_inScope_NS satisfies not($x =
get-namespace-uri-for-prefix($me,$x))">
	<xsl:value-of select="concat('  (unused)',$newline)"/>
      </xsl:if>
    </xsl:for-each-group>
  </xsl:template>

<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>

</xsl:stylesheet>


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.