tags:

views:

290

answers:

2

Below is a snippet of what you get when you save the configuration of IIS 6/Windows Server 2003 web sites to a file:

<?xml version ="1.0"?>
<configuration xmlns="urn:microsoft-catalog:XML_Metabase_V64_0">
<MBProperty>
<IIsWebServer   Location ="/LM/W3SVC/1"
     AppPoolId="DefaultAppPool"
     DefaultDoc="Default.htm,Default.asp,index.htm,iisstart.htm,Default.aspx"
 ServerAutoStart="FALSE"
 ServerBindings=":80:"
 ServerComment="Default Web Site"
 ServerSize="1"
>
</IIsWebServer>
<IIsWebServer   Location ="/LM/W3SVC/1020944513"
 AuthFlags="0"
 LogPluginClsid="{FF160663-DE82-11CF-BC0A-00AA006111E0}"
 ServerAutoStart="TRUE"
 ServerBindings="161.230.8.183:80:"
 ServerComment="staging.magazinefundraising.com"
>
</IIsWebServer>
<IIsWebServer   Location ="/LM/W3SVC/103632312"
 AuthFlags="0"
 LogPluginClsid="{FF160663-DE82-11CF-BC0A-00AA006111E0}"
 ServerAutoStart="TRUE"
 ServerBindings="161.230.9.48:80:"
 ServerComment="QSP2.Downtime"
>
</IIsWebServer>
</MBProperty>
</configuration>

As you can see, there are multiple <IIsWebServer> sections between the <MBProperty> and </MBProperty> elements.

I'd like to create a simple xsl stylesheet which outputs a multi-column (tabular) result containing the following attributes for each IIsWebServer instance:

ServerComment
ServerBindings
AuthFlags

So the result might look something like:

ServerComment     ServerBindings     AuthFlags  
-------------     --------------     ---------  
QSP2.Downtime     161.230.9.48:80:   0

and so on...

Thanks!

+3  A: 

XSL could be something like this:

<?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"
    xmlns:mb="urn:microsoft-catalog:XML_Metabase_V64_0"
    exclude-result-prefixes="msxsl">
    <xsl:output method="text" indent="yes"/>

    <xsl:template match="/">
      ServerComment&#160;&#160;&#160;ServerBindings&#160;&#160;&#160;AuthFlags

      <xsl:apply-templates />
    </xsl:template>

  <xsl:template match="mb:IIsWebServer">

    <xsl:value-of select="./@ServerComment" />
    <xsl:text>&#160;</xsl:text>
    <xsl:value-of select="./@ServerBindings" />
    <xsl:text>&#160;</xsl:text>
    <xsl:value-of select="./@AuthFlags" />

  </xsl:template>
</xsl:stylesheet>

OF course, you'll want to prettify it :-) but it basically works.

Whether it's the right choice and best technology to use for this, is totally up to you :-) But it can be done - no problem.

Marc

marc_s
Marc - terrific response, thank you much
Matt
Marc - one other thing for you - I'm having trouble getting the output to show tabular - even when I include a <table> definition around the attributes it still all shows on one big long wrapped line. Thoughts?thanks
Matt
OK, so now you're trying to output HTML, right? Did you change the <xsl:output> to say <xsl:output method="HTML"> ??
marc_s
Good point. :) Thx again Marc.
Matt
A: 

As Emil said, XSL isn't exactly made for text formatting. However, you should be able to achieve your goal if you output HTML. Something like the following:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    <xsl:template match="/">
<table>
    <tr>
        <th>ServerComment</th>
        <th>ServerBindings</th>
        <th>AuthFlags</th>
    </tr>
        <xsl:for-each select="/configuration/MBProperty/IIsWebServer">
    <tr>
        <td><xsl:value-of select="@ServerComment" /></td>
        <td><xsl:value-of select="@ServerBindings" /></td>
        <td><xsl:value-of select="@AuthFlags" /></td>
    </tr>
        </xsl:for-each>
</table>
    </xsl:template>
</xsl:stylesheet>

If you're going for developing a tabular display for viewing purposes only, this may be your best bet. However, if you're planning on using the data in another way, it may be better to go with Marc or Emil's approach.

cmptrgeekken