How to pull a specific name within a node when using an XSL Stylesheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GabeGGG
    New Member
    • Mar 2010
    • 17

    #1

    How to pull a specific name within a node when using an XSL Stylesheet

    I’ve very new to XML and making XSL stylesheets. Currently I have a bunch of Exchange Servers listed throughout my XML document. All the Exchange Servers are located within the node:
    Code:
    DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster
    within the XML document.

    In my XSL stylesheet I’ve been calling out the exchange server individually by name. (example):

    Code:
     for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com'] | DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']”>.
    As you can see if one has multiple servers the stylesheet will get rather congested calling out each server. I want to know if there is a way that I can display all the Exchange servers by using: contoso.microso f.com instead of inputing each server names entire FQDN individually. I want one rule for all Exchange servers so that I don’t have to make a a rule for each within the atribute for-each select .

    Below is my XML document and my XSL Stylesheet.

    XML Document (Had to modify this a little because the XML file is huge):
    Code:
    <Key ScopeClass="Global">
    					<SchemaId Namespace="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" ElementName="Topology" />
    					<AuthorityId Class="Host" InstanceId="00000000-0000-0000-0000-000000000000" />
    				</Key>
    				<Dictionary Count="1">
    					<Item>
    						<Key />
    						<Value Signature="d68c994c-9b4c-4bac-8659-7709d1639352">
    							<Topology xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" schemaLocation="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008 ..\..\..\..\dev\server\Squid\Schemas\Deploy\Topology.2008.xsd">
    								<InternalDomains AllowAllDomains="false" DefaultDomain="microsoft.com">
    									<InternalDomain Name="microsoft.com" Authoritative="false" />
    								</InternalDomains>
    								<Sites>
    									<CentralSite SiteId="tk5">
    										<Name>Exchange</Name>
    										<Location CountryCode="US" City="Quincy" State="WA" />
    									</CentralSite>
    									<CentralSite SiteId="tukwila">
    										<Name>Tukwila</Name>
    										<Location CountryCode="US" City="Tukwila" State="WA" />
    										<SiteConfiguration Type="Microsoft.Rtc.Management.Deploy.Internal.SiteConfigurations.OCSSiteConfiguration">
    											<OCSSiteConfiguration xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.SiteConfigurations.2008">
    												<FederationRoute>
    													<ServiceId xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" SiteId="BackCompatSite" RoleName="Registrar" Instance="7" />
    												</FederationRoute>
    											</OCSSiteConfiguration>
    										</SiteConfiguration>
    									</CentralSite>
    									<CentralSite SiteId="BackCompatSite">
    										<Name>BackCompatSite</Name>
    									</CentralSite>
    									<RemoteSite SiteId="bo_tc" CentralSiteId="tk5">
    										<Name>Tacoma Branch</Name>
    										<Location CountryCode="US" City="Tacoma" State="WA" />
    									</RemoteSite>
    								</Sites>
    								<Clusters>
    									<Cluster Fqdn="exch-dc-08.contoso.microsoft.com" RequiresReplication="false" RequiresSetup="false">
    										<ClusterId SiteId="tk5" Number="1" />
    										<Machine OrdinalInCluster="1" Fqdn="exch-dc-08.contoso.microsoft.com">
    											<NetInterface InterfaceSide="Primary" InterfaceNumber="1" IPAddress="1.1.1.1" />
    										</Machine>
    									</Cluster>
    									<Cluster Fqdn="tk5ucdfpp01.contoso.microsoft.com" RequiresReplication="false" RequiresSetup="false">
    										<ClusterId SiteId="tk5" Number="2" />
    										<Machine OrdinalInCluster="1" Fqdn="tk5ucdfpp01.contoso.microsoft.com">
    											<NetInterface InterfaceSide="External" InterfaceNumber="1" IPAddress="2.2.2.2" />
    											<NetInterface InterfaceSide="Primary" InterfaceNumber="1" IPAddress="2.2.2.2" />
    										</Machine>
    									</Cluster>
    									<Cluster Fqdn="b43ucdfms01.contoso.microsoft.com" RequiresReplication="false" RequiresSetup="false">
    										<ClusterId SiteId="tk5" Number="3" />
    										<Machine OrdinalInCluster="1" Fqdn="b43ucdfms01.contoso.microsoft.com">
    											<NetInterface InterfaceSide="Primary" InterfaceNumber="1" IPAddress="3.3.3.3" />
    											<NetInterface InterfaceSide="Pstn" InterfaceNumber="1" IPAddress="3.3.3.3" />
    										</Machine>
                                                                            </Cluster>
    + <SqlInstances>
    + <Services>
    </Topology>
    </Value>
    </Item>
    </Dictionary>
    </AnchoredXml>
    </Data>
    </DocItem>
    + <DocItem Name>
    </DocItemSet>
    XSLT Stylesheet
    Code:
    <?xml version='1.0'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
      <html>
       <body>
         <body bgcolor="Silver">
       </body>
         <h2>Exchange Server Information</h2>
         <table border="3"> 
          <tr bgcolor="yellow">
          	<th>Exchange Servers</th>
            <th>Replication Required</th>
            <th>Setup Required</th>
            <th>Network Interface</th>
            <th>IP Address</th>
          </tr>	
          <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com']|
               DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']|
               DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='b43ucdfms01.contoso.microsoft.com']|
     
               DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='1.1.1.1']|
               DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='2.2.2.2']|
               DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='3.3.3.3']">
          <tr>
               
               <td><xsl:value-of select="@Fqdn"/></td>
               <td><xsl:value-of select="@RequiresReplication"/></td>
               <td><xsl:value-of select="@RequiresSetup"/></td>
               <td><xsl:value-of select="@InterfaceSide"/></td>
               <td><xsl:value-of select="@IPAddress"/></td>
          </tr>
          </xsl:for-each>
        </table>
       </body>
      </html>
    </xsl:template>
    </xsl:stylesheet>
    Attached is a screenshoot of my XML output table.
    Attached Files
    Last edited by jkmyoung; Apr 5 '10, 07:29 PM. Reason: [code][/code]
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Do either of these work?
    Code:
    <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster"> OR
    
    <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(.,'contoso.microsoft.com')]">

    Comment

    • GabeGGG
      New Member
      • Mar 2010
      • 17

      #3
      The first option you gave me pulled all of the servers even the ones with different FQDN's . I get the error below for the 2nd option you gave me:

      Code:
      [Unknown method. DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[-->contains(.<--,'exch...

      Tried the below XSLT Stylesheet
      Code:
      <?xml version='1.0'?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      <xsl:template match="/">
        <html>
         <body>
           <body bgcolor="Silver">
         </body>
           <h2>Exchange Server Information</h2>
           <table border="3"> 
            <tr bgcolor="yellow">
            	<th>Exchange Servers</th>
              <th>Replication Required</th>
              <th>Setup Required</th>
              <th>Network Interface</th>
              <th>IP Address</th>
            </tr>	
            <xsl:for-each select="[B]DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(.,'contoso.microsoft.com')]|[/B]
                                  DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='1.1.1.1']| 
                                  DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='2.2.2.2']| 
                                  DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='3.3.3.3']"> 
            <tr>
                 
                 <td><xsl:value-of select="@Fqdn"/></td>
                 <td><xsl:value-of select="@RequiresReplication"/></td>
                 <td><xsl:value-of select="@RequiresSetup"/></td>
                 <td><xsl:value-of select="@InterfaceSide"/></td>
                 <td><xsl:value-of select="@IPAddress"/></td>
            </tr>
            </xsl:for-each>
          </table>
         </body>
        </html>
      </xsl:template>
      </xsl:stylesheet>

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Are you using MSXML 3 or earlier? How are you running the transformation?
        You may need to set something like:
        oXMLDoc.setProp erty("Selection Language", "XPath");

        Is substring-after supported?, eg:
        Code:
        <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[substring-after(@Fqdn,'.') = 'contoso.microsoft.com']">

        Comment

        • GabeGGG
          New Member
          • Mar 2010
          • 17

          #5
          I'm not 100% sure if I'm running MSXML 3 or earlier. When I open the XML document it says "<?xml version="1.0" encoding="utf-8" ?> " at the top.

          I'm taking an XML document that someone gave me and making an XSL stylesheet so that the XML document can be visable in a template format. I'll open the XML doc in notepad and point it to my XSL document and save it. Then I'll customize my XSL document. When I open the XML document it will display the data.

          Below is the info I added to my last XSL document that you sent me last.
          Code:
          <?xml version='1.0'?>
          <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
          <xsl:template match="/">
            <html>
             <body>
               <body bgcolor="Silver">
             </body>
               <h2>Exchange Server Information</h2>
               <table border="3"> 
                <tr bgcolor="yellow">
                	<th>Exchange Servers</th>
                  <th>Replication Required</th>
                  <th>Setup Required</th>
                  <th>Network Interface</th>
                  <th>IP Address</th>
                </tr>	
                <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[substring-after(@Fqdn,'.')='contoso.microsoft.com']|
          
                                      DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='157.54.98.16']| 
                                      DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='157.54.61.141']| 
                                      DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='10.31.127.204']"> 
                <tr>
                     
                     <td><xsl:value-of select="@Fqdn"/></td>
                     <td><xsl:value-of select="@RequiresReplication"/></td>
                     <td><xsl:value-of select="@RequiresSetup"/></td>
                     <td><xsl:value-of select="@InterfaceSide"/></td>
                     <td><xsl:value-of select="@IPAddress"/></td>
                </tr>
                </xsl:for-each>
              </table>
             </body>
            </html>
          </xsl:template>
          </xsl:stylesheet>

          Comment

          • Niheel
            Recognized Expert Moderator Top Contributor
            • Jul 2005
            • 2433

            #6
            use code tags to display all your code:

            [code] . . . . [/code]

            niheel @ bytes

            Comment

            • GabeGGG
              New Member
              • Mar 2010
              • 17

              #7
              kub365 I'm not sure what you mean by code tags? I'm very new to this site and XML and XSL. Sorry for the troubles.

              Comment

              • jkmyoung
                Recognized Expert Top Contributor
                • Mar 2006
                • 2057

                #8
                If you change your stylesheet element to:
                <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
                does it work?

                code tags &#91;code] [/code]
                Represented by the # in the quick reply box, next to quote

                Comment

                • GabeGGG
                  New Member
                  • Mar 2010
                  • 17

                  #9
                  jkmyoung

                  I get the below when I use the code below: Also see first picture for outcome.
                  Code:
                  <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[substring-after(@Fqdn,'.') = 'contoso.microsoft.com']">
                  Stylesheet

                  Code:
                  <<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                  <xsl:template match="/">
                    <html>
                     <body>
                       <body bgcolor="Silver">
                     </body>
                       <h2>Exchange Server Information</h2>
                       <table border="3"> 
                        <tr bgcolor="yellow">
                        	<th>Exchange Servers</th>
                          <th>Replication Required</th>
                          <th>Setup Required</th>
                          <th>Network Interface</th>
                          <th>IP Address</th>
                        </tr>	
                        <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[substring-after(@Fqdn,'.') = 'contoso.microsoft.com']"> 
                        <tr>
                             
                             <td><xsl:value-of select="@Fqdn"/></td>
                             <td><xsl:value-of select="@RequiresReplication"/></td>
                             <td><xsl:value-of select="@RequiresSetup"/></td>
                             <td><xsl:value-of select="@InterfaceSide"/></td>
                             <td><xsl:value-of select="@IPAddress"/></td>
                        </tr>
                        </xsl:for-each>
                      </table>
                     </body>
                    </html>
                  </xsl:template>
                  </xsl:stylesheet>

                  When I use code:
                  Code:
                   <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(.,'contoso.microsoft.com')]">
                  I get the same output as my other screenshoot.

                  Stylesheet used:

                  Code:
                  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                  <xsl:template match="/">
                    <html>
                     <body>
                       <body bgcolor="Silver">
                     </body>
                       <h2>Exchange Server Information</h2>
                       <table border="3"> 
                        <tr bgcolor="yellow">
                        	<th>Exchange Servers</th>
                          <th>Replication Required</th>
                          <th>Setup Required</th>
                          <th>Network Interface</th>
                          <th>IP Address</th>
                        </tr>	
                        <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(.,'contoso.microsoft.com')]"> 
                    
                  
                        <tr>
                             
                             <td><xsl:value-of select="@Fqdn"/></td>
                             <td><xsl:value-of select="@RequiresReplication"/></td>
                             <td><xsl:value-of select="@RequiresSetup"/></td>
                             <td><xsl:value-of select="@InterfaceSide"/></td>
                             <td><xsl:value-of select="@IPAddress"/></td>
                        </tr>
                        </xsl:for-each>
                      </table>
                     </body>
                    </html>
                  </xsl:template>
                  </xsl:stylesheet>
                  Attached Files

                  Comment

                  • GabeGGG
                    New Member
                    • Mar 2010
                    • 17

                    #10
                    Do I need to change my XML sheet as well? It shows that its using.

                    <?xml version="1.0" encoding="utf-8"?>
                    <?xml-stylesheet type="text/xsl" href="DocItemSe tV10.xsl"?>

                    Gabe

                    Comment

                    • jkmyoung
                      Recognized Expert Top Contributor
                      • Mar 2006
                      • 2057

                      #11
                      I made a mistake in the original posting:
                      contains(.,'con toso.microsoft. com')]">
                      should be
                      contains(@Fqdn, 'contoso.micros oft.com')]">

                      To execute these stylesheets, you are simply opening the xml in an internet browser window correct? Which browser are you using?

                      Comment

                      • GabeGGG
                        New Member
                        • Mar 2010
                        • 17

                        #12
                        Yes, I'm opening the xml in an Internet browser window. The browser I'm using is Internet Explorere 8.

                        When I add
                        Code:
                        <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(@Fqdn,'exchange.corp.microsoft.com')]">
                        I get the same output as in my last screenshot.

                        Below is the Stylesheet I'm using. (Does it look correct?)

                        Code:
                        [B]<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">[/B]
                        <xsl:template match="/">
                          <html>
                           <body>
                             <body bgcolor="Silver">
                           </body>
                             <h2>Exchange Server Information</h2>
                             <table border="3"> 
                              <tr bgcolor="yellow">
                              	<th>Exchange Servers</th>
                                <th>Replication Required</th>
                                <th>Setup Required</th>
                                <th>Network Interface</th>
                                <th>IP Address</th>
                              </tr>	
                             <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(@Fqdn,'contoso.microsoft.com')]">
                              <tr>
                                   
                                   <td><xsl:value-of select="@Fqdn"/></td>
                                   <td><xsl:value-of select="@RequiresReplication"/></td>
                                   <td><xsl:value-of select="@RequiresSetup"/></td>
                                   <td><xsl:value-of select="@InterfaceSide"/></td>
                                   <td><xsl:value-of select="@IPAddress"/></td>
                              </tr>
                              </xsl:for-each>
                            </table>
                           </body>
                          </html>
                        </xsl:template>
                        </xsl:stylesheet>

                        Comment

                        • GabeGGG
                          New Member
                          • Mar 2010
                          • 17

                          #13
                          Originally posted by jkmyoung
                          I made a mistake in the original posting:
                          contains(.,'con toso.microsoft. com')]">
                          should be
                          contains(@Fqdn, 'contoso.micros oft.com')]">

                          To execute these stylesheets, you are simply opening the xml in an internet browser window correct? Which browser are you using?
                          jkmyoung

                          I’m still having some issues with this one. I still can’t pull out the exchange servers by name.

                          Thanks,

                          Gabe

                          Comment

                          • jkmyoung
                            Recognized Expert Top Contributor
                            • Mar 2006
                            • 2057

                            #14
                            Please try visiting http://www.bayes.co.uk/xml/index.xml...ml_sniffer.htm
                            to determine the version of msxml you have.

                            In order to be able to use contains, you might have to install an msxml upgrade.

                            If you have other clients that use this, you may need to provide a disclaimer that they must have msxml of some version installed, or be using a different browser.

                            According to this page: http://support.microsoft.com/kb/304265 contains is available once you have the appropriate updates.

                            Comment

                            • GabeGGG
                              New Member
                              • Mar 2010
                              • 17

                              #15
                              Originally posted by jkmyoung
                              Please try visiting http://www.bayes.co.uk/xml/index.xml...ml_sniffer.htm
                              to determine the version of msxml you have.

                              In order to be able to use contains, you might have to install an msxml upgrade.

                              If you have other clients that use this, you may need to provide a disclaimer that they must have msxml of some version installed, or be using a different browser.

                              According to this page: http://support.microsoft.com/kb/304265 contains is available once you have the appropriate updates.
                              I went to the site http://www.bayes.co.uk/xml/index.xml...ml_sniffer.htm and received the below output (See screenshot).

                              In the screenshoot it says "Although you have the new version of MSXML you are running it in "side-by-side" mode. To get the full benifits of this new version you should run xmlinst (from Microsoft to switch to "replace" mode."

                              Do I need to run it in replace mode? Could this affect some of my other changes that I have created in my stylesheet?

                              Thankls,

                              Gabe
                              Attached Files

                              Comment

                              Working...