Question Trying to create a transform, stuck on xsl:for-each

StoneCodeMonkey

Well-known member
Joined
Apr 17, 2009
Messages
56
Programming Experience
5-10
I'm trying to create a transform, for the first time, and could use a few pointers.

I am applying the transform to an XML Comment Document produced from Visual Studio. The general structure of the XML file is:

VB.NET:
<doc>
  <assembly>
    <name>MyAssembly</name>
  </assembly>
  <members>
    <member name="T:MyNamespace.MyClasses.MyClass">
      <summary>
        Provides access to instances of the.
      </summary>
    </member>
    <member name="M:MyNamespace.MyClasses.MyClass.#ctor">
      <summary>
        Initializes a new instance of the <see cref="MyNamespace.MyClasses.MyClass" /> class.
      </summary>
    </member>
  </members>
</doc>

I'm trying to start simple, just getting the assembly name and then looping over the members to return the name. The transform I have thus far...

VB.NET:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="html"/>
  
  <!--Locates the Assembly Name and Stores for reference-->
  <xsl:variable name="AssemblyName">
    <xsl:value-of select="doc/assembly/name"/>
  </xsl:variable>

  <!--Reads entire contents of XML file.-->
  <xsl:template match="doc">
    <!--Create an HTML output-->
    <html>
      <body>
        <h1>
          Visual Studio XML Comment Documentation for
          <tt style="font-size: inherit; color: #0000FF; font-style: inherit; font-family: inherit; font-weight: inherit; font-variant: inherit; text-decoration: underline;">
            <xsl:value-of select="$AssemblyName"/>
          </tt>
        </h1>
        <xsl:for-each select="member">
          <p>
            <xsl:value-of select="name"/>
          </p>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

The only part that works is getting the Assembly name.

I would have thought that the for-each would have simply inserted <p> member name<p/> for each member in the collection.
VB.NET:
<xsl:for-each select="member">
          <p>
            <xsl:value-of select="name"/>
          </p>
        </xsl:for-each>
Can anyone tell me what I am missing?

Regards,
 
Updated Template

This works for getting each member.

VB.NET:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="html"/>

  <!--Locates the Assembly Name and Stores for reference-->
  <xsl:variable name="AssemblyName">
    <xsl:value-of select="doc/assembly/name"/>
  </xsl:variable>

  <!--Reads entire contents of XML file.-->
  <xsl:template match="doc">
    <!--Create an HTML output-->
    <html>
      <body>
        <h1>
          Visual Studio XML Comment Documentation for
          <tt style="font-size: inherit; color: #0000FF; font-style: inherit; font-family: inherit; font-weight: inherit; font-variant: inherit; text-decoration: underline;">
            <xsl:value-of select="$AssemblyName"/>
          </tt>
        </h1>

        <xsl:apply-templates select="members"/>

      </body>
    </html>
  </xsl:template>

  <xsl:template match="members">
    <xsl:for-each select="member">
      <p>
        <xsl:value-of select="@name"/>
      </p>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Now just to figure our how to process all of the possible data in each member.

Regards,
 
What Is The Best Approach Parsing the XML File

Ok, home from work, time to go at this again.

So, far I have found that getting the Assembly name and all of the member names is pretty straight forward. However, after that it becomes allot more difficult.

So before the questions, a little background...

Article on MSDN
Documenting Your Code With XML Comments

Documenting Your Code with XML

List of XML tags I would expect to find in the XML file.
Recommended XML Tags for Documentation Comments

ID strings embedded in the file.
Processing the XML File

So, when I started looking through the file I found tags that are not listed in the "Recommended XML Tags" documentation.

Undocumented XML Tags Produced by Visual Studio
<filterpriority>2</filterpriority>
FiltorPriority affects Visual Studio Intellisense as mentioned in this MSDN article.
Documenting Your Code With XML Comments

<PermissionSet>
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
</PermissionSet>
http://msdn.microsoft.com/en-us/library/thd4h5h0.aspx</P>

I thought there should be a better means of identifying all of the elements and attributes in the XML with writing code to iterate over the entire file. Turns out you can infer a schema from the source xml file which helps to identify every possible element and attribute.

Pop this in a Console app and point to am XML file to see the schema.
VB.NET:
Dim reader As XmlReader = XmlReader.Create("C:\My\WebSites\VS2010 XML Comment Documentation\SampleVsXmlCommentDocument.xml")
        Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()
        Dim schema As XmlSchemaInference = New XmlSchemaInference()

        schemaSet = schema.InferSchema(reader)
        For Each s As XmlSchema In schemaSet.Schemas()
            s.Write(Console.Out)
        Next

        Console.Read()

Also, open one of the XML files from the Framework folder in VS, use the Create Schema tool. You will see a nice treeview of the schema in the Schema Explorer.

What I was thinking is that I should be able to iterate over each "Member" using the Schema. Not that every member shares the same number of child elements or attributes.

But I just don't have any experience in the XML namespace. Does anyone have any guidance on where to start? Basically, I want to output for each member it parameters and the info from the XML comments.

Regards,
 
Back
Top