469,366 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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

17
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:
Expand|Select|Wrap|Line Numbers
  1. 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):

Expand|Select|Wrap|Line Numbers
  1.  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.microsof.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):
Expand|Select|Wrap|Line Numbers
  1. <Key ScopeClass="Global">
  2.                     <SchemaId Namespace="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" ElementName="Topology" />
  3.                     <AuthorityId Class="Host" InstanceId="00000000-0000-0000-0000-000000000000" />
  4.                 </Key>
  5.                 <Dictionary Count="1">
  6.                     <Item>
  7.                         <Key />
  8.                         <Value Signature="d68c994c-9b4c-4bac-8659-7709d1639352">
  9.                             <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">
  10.                                 <InternalDomains AllowAllDomains="false" DefaultDomain="microsoft.com">
  11.                                     <InternalDomain Name="microsoft.com" Authoritative="false" />
  12.                                 </InternalDomains>
  13.                                 <Sites>
  14.                                     <CentralSite SiteId="tk5">
  15.                                         <Name>Exchange</Name>
  16.                                         <Location CountryCode="US" City="Quincy" State="WA" />
  17.                                     </CentralSite>
  18.                                     <CentralSite SiteId="tukwila">
  19.                                         <Name>Tukwila</Name>
  20.                                         <Location CountryCode="US" City="Tukwila" State="WA" />
  21.                                         <SiteConfiguration Type="Microsoft.Rtc.Management.Deploy.Internal.SiteConfigurations.OCSSiteConfiguration">
  22.                                             <OCSSiteConfiguration xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.SiteConfigurations.2008">
  23.                                                 <FederationRoute>
  24.                                                     <ServiceId xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" SiteId="BackCompatSite" RoleName="Registrar" Instance="7" />
  25.                                                 </FederationRoute>
  26.                                             </OCSSiteConfiguration>
  27.                                         </SiteConfiguration>
  28.                                     </CentralSite>
  29.                                     <CentralSite SiteId="BackCompatSite">
  30.                                         <Name>BackCompatSite</Name>
  31.                                     </CentralSite>
  32.                                     <RemoteSite SiteId="bo_tc" CentralSiteId="tk5">
  33.                                         <Name>Tacoma Branch</Name>
  34.                                         <Location CountryCode="US" City="Tacoma" State="WA" />
  35.                                     </RemoteSite>
  36.                                 </Sites>
  37.                                 <Clusters>
  38.                                     <Cluster Fqdn="exch-dc-08.contoso.microsoft.com" RequiresReplication="false" RequiresSetup="false">
  39.                                         <ClusterId SiteId="tk5" Number="1" />
  40.                                         <Machine OrdinalInCluster="1" Fqdn="exch-dc-08.contoso.microsoft.com">
  41.                                             <NetInterface InterfaceSide="Primary" InterfaceNumber="1" IPAddress="1.1.1.1" />
  42.                                         </Machine>
  43.                                     </Cluster>
  44.                                     <Cluster Fqdn="tk5ucdfpp01.contoso.microsoft.com" RequiresReplication="false" RequiresSetup="false">
  45.                                         <ClusterId SiteId="tk5" Number="2" />
  46.                                         <Machine OrdinalInCluster="1" Fqdn="tk5ucdfpp01.contoso.microsoft.com">
  47.                                             <NetInterface InterfaceSide="External" InterfaceNumber="1" IPAddress="2.2.2.2" />
  48.                                             <NetInterface InterfaceSide="Primary" InterfaceNumber="1" IPAddress="2.2.2.2" />
  49.                                         </Machine>
  50.                                     </Cluster>
  51.                                     <Cluster Fqdn="b43ucdfms01.contoso.microsoft.com" RequiresReplication="false" RequiresSetup="false">
  52.                                         <ClusterId SiteId="tk5" Number="3" />
  53.                                         <Machine OrdinalInCluster="1" Fqdn="b43ucdfms01.contoso.microsoft.com">
  54.                                             <NetInterface InterfaceSide="Primary" InterfaceNumber="1" IPAddress="3.3.3.3" />
  55.                                             <NetInterface InterfaceSide="Pstn" InterfaceNumber="1" IPAddress="3.3.3.3" />
  56.                                         </Machine>
  57.                                                                         </Cluster>
  58. + <SqlInstances>
  59. + <Services>
  60. </Topology>
  61. </Value>
  62. </Item>
  63. </Dictionary>
  64. </AnchoredXml>
  65. </Data>
  66. </DocItem>
  67. + <DocItem Name>
  68. </DocItemSet>
  69.  
XSLT Stylesheet
Expand|Select|Wrap|Line Numbers
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  3. <xsl:template match="/">
  4.   <html>
  5.    <body>
  6.      <body bgcolor="Silver">
  7.    </body>
  8.      <h2>Exchange Server Information</h2>
  9.      <table border="3"> 
  10.       <tr bgcolor="yellow">
  11.           <th>Exchange Servers</th>
  12.         <th>Replication Required</th>
  13.         <th>Setup Required</th>
  14.         <th>Network Interface</th>
  15.         <th>IP Address</th>
  16.       </tr>    
  17.       <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com']|
  18.            DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']|
  19.            DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='b43ucdfms01.contoso.microsoft.com']|
  20.  
  21.            DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='1.1.1.1']|
  22.            DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='2.2.2.2']|
  23.            DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='3.3.3.3']">
  24.       <tr>
  25.  
  26.            <td><xsl:value-of select="@Fqdn"/></td>
  27.            <td><xsl:value-of select="@RequiresReplication"/></td>
  28.            <td><xsl:value-of select="@RequiresSetup"/></td>
  29.            <td><xsl:value-of select="@InterfaceSide"/></td>
  30.            <td><xsl:value-of select="@IPAddress"/></td>
  31.       </tr>
  32.       </xsl:for-each>
  33.     </table>
  34.    </body>
  35.   </html>
  36. </xsl:template>
  37. </xsl:stylesheet>
  38.  
Attached is a screenshoot of my XML output table.
Attached Images
File Type: jpg Example.jpg (18.3 KB, 295 views)
Apr 5 '10 #1
16 2807
jkmyoung
2,057 Expert 2GB
Do either of these work?
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster"> OR
  2.  
  3. <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(.,'contoso.microsoft.com')]">
  4.  
Apr 5 '10 #2
GabeGGG
17
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:

Expand|Select|Wrap|Line Numbers
  1. [Unknown method. DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[-->contains(.<--,'exch...

Tried the below XSLT Stylesheet
Expand|Select|Wrap|Line Numbers
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  3. <xsl:template match="/">
  4.   <html>
  5.    <body>
  6.      <body bgcolor="Silver">
  7.    </body>
  8.      <h2>Exchange Server Information</h2>
  9.      <table border="3"> 
  10.       <tr bgcolor="yellow">
  11.           <th>Exchange Servers</th>
  12.         <th>Replication Required</th>
  13.         <th>Setup Required</th>
  14.         <th>Network Interface</th>
  15.         <th>IP Address</th>
  16.       </tr>    
  17.       <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(.,'contoso.microsoft.com')]|
  18.                             DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='1.1.1.1']| 
  19.                             DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='2.2.2.2']| 
  20.                             DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='3.3.3.3']"> 
  21.       <tr>
  22.  
  23.            <td><xsl:value-of select="@Fqdn"/></td>
  24.            <td><xsl:value-of select="@RequiresReplication"/></td>
  25.            <td><xsl:value-of select="@RequiresSetup"/></td>
  26.            <td><xsl:value-of select="@InterfaceSide"/></td>
  27.            <td><xsl:value-of select="@IPAddress"/></td>
  28.       </tr>
  29.       </xsl:for-each>
  30.     </table>
  31.    </body>
  32.   </html>
  33. </xsl:template>
  34. </xsl:stylesheet>
  35.  
Apr 5 '10 #3
jkmyoung
2,057 Expert 2GB
Are you using MSXML 3 or earlier? How are you running the transformation?
You may need to set something like:
oXMLDoc.setProperty("SelectionLanguage", "XPath");

Is substring-after supported?, eg:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[substring-after(@Fqdn,'.') = 'contoso.microsoft.com']">
  2.  
Apr 5 '10 #4
GabeGGG
17
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.
Expand|Select|Wrap|Line Numbers
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  3. <xsl:template match="/">
  4.   <html>
  5.    <body>
  6.      <body bgcolor="Silver">
  7.    </body>
  8.      <h2>Exchange Server Information</h2>
  9.      <table border="3"> 
  10.       <tr bgcolor="yellow">
  11.           <th>Exchange Servers</th>
  12.         <th>Replication Required</th>
  13.         <th>Setup Required</th>
  14.         <th>Network Interface</th>
  15.         <th>IP Address</th>
  16.       </tr>    
  17.       <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[substring-after(@Fqdn,'.')='contoso.microsoft.com']|
  18.  
  19.                             DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='157.54.98.16']| 
  20.                             DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='157.54.61.141']| 
  21.                             DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='10.31.127.204']"> 
  22.       <tr>
  23.  
  24.            <td><xsl:value-of select="@Fqdn"/></td>
  25.            <td><xsl:value-of select="@RequiresReplication"/></td>
  26.            <td><xsl:value-of select="@RequiresSetup"/></td>
  27.            <td><xsl:value-of select="@InterfaceSide"/></td>
  28.            <td><xsl:value-of select="@IPAddress"/></td>
  29.       </tr>
  30.       </xsl:for-each>
  31.     </table>
  32.    </body>
  33.   </html>
  34. </xsl:template>
  35. </xsl:stylesheet>
  36.  
Apr 5 '10 #5
Niheel
2,431 Expert Mod 2GB
use code tags to display all your code:

[code] . . . . [/code]

Apr 5 '10 #6
GabeGGG
17
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.
Apr 5 '10 #7
jkmyoung
2,057 Expert 2GB
If you change your stylesheet element to:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
does it work?

code tags [code] [/code]
Represented by the # in the quick reply box, next to quote
Apr 6 '10 #8
GabeGGG
17
jkmyoung

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

Expand|Select|Wrap|Line Numbers
  1. <<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:template match="/">
  3.   <html>
  4.    <body>
  5.      <body bgcolor="Silver">
  6.    </body>
  7.      <h2>Exchange Server Information</h2>
  8.      <table border="3"> 
  9.       <tr bgcolor="yellow">
  10.           <th>Exchange Servers</th>
  11.         <th>Replication Required</th>
  12.         <th>Setup Required</th>
  13.         <th>Network Interface</th>
  14.         <th>IP Address</th>
  15.       </tr>    
  16.       <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[substring-after(@Fqdn,'.') = 'contoso.microsoft.com']"> 
  17.       <tr>
  18.  
  19.            <td><xsl:value-of select="@Fqdn"/></td>
  20.            <td><xsl:value-of select="@RequiresReplication"/></td>
  21.            <td><xsl:value-of select="@RequiresSetup"/></td>
  22.            <td><xsl:value-of select="@InterfaceSide"/></td>
  23.            <td><xsl:value-of select="@IPAddress"/></td>
  24.       </tr>
  25.       </xsl:for-each>
  26.     </table>
  27.    </body>
  28.   </html>
  29. </xsl:template>
  30. </xsl:stylesheet>
  31.  

When I use code:
Expand|Select|Wrap|Line Numbers
  1.  <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:

Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:template match="/">
  3.   <html>
  4.    <body>
  5.      <body bgcolor="Silver">
  6.    </body>
  7.      <h2>Exchange Server Information</h2>
  8.      <table border="3"> 
  9.       <tr bgcolor="yellow">
  10.           <th>Exchange Servers</th>
  11.         <th>Replication Required</th>
  12.         <th>Setup Required</th>
  13.         <th>Network Interface</th>
  14.         <th>IP Address</th>
  15.       </tr>    
  16.       <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(.,'contoso.microsoft.com')]"> 
  17.  
  18.  
  19.       <tr>
  20.  
  21.            <td><xsl:value-of select="@Fqdn"/></td>
  22.            <td><xsl:value-of select="@RequiresReplication"/></td>
  23.            <td><xsl:value-of select="@RequiresSetup"/></td>
  24.            <td><xsl:value-of select="@InterfaceSide"/></td>
  25.            <td><xsl:value-of select="@IPAddress"/></td>
  26.       </tr>
  27.       </xsl:for-each>
  28.     </table>
  29.    </body>
  30.   </html>
  31. </xsl:template>
  32. </xsl:stylesheet>
  33.  
Attached Images
File Type: jpg Example3.jpg (7.9 KB, 168 views)
Apr 6 '10 #9
GabeGGG
17
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="DocItemSetV10.xsl"?>

Gabe
Apr 6 '10 #10
jkmyoung
2,057 Expert 2GB
I made a mistake in the original posting:
contains(.,'contoso.microsoft.com')]">
should be
contains(@Fqdn,'contoso.microsoft.com')]">

To execute these stylesheets, you are simply opening the xml in an internet browser window correct? Which browser are you using?
Apr 6 '10 #11
GabeGGG
17
Yes, I'm opening the xml in an Internet browser window. The browser I'm using is Internet Explorere 8.

When I add
Expand|Select|Wrap|Line Numbers
  1. <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?)

Expand|Select|Wrap|Line Numbers
  1.  
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:template match="/">
  4.   <html>
  5.    <body>
  6.      <body bgcolor="Silver">
  7.    </body>
  8.      <h2>Exchange Server Information</h2>
  9.      <table border="3"> 
  10.       <tr bgcolor="yellow">
  11.           <th>Exchange Servers</th>
  12.         <th>Replication Required</th>
  13.         <th>Setup Required</th>
  14.         <th>Network Interface</th>
  15.         <th>IP Address</th>
  16.       </tr>    
  17.      <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[contains(@Fqdn,'contoso.microsoft.com')]">
  18.       <tr>
  19.  
  20.            <td><xsl:value-of select="@Fqdn"/></td>
  21.            <td><xsl:value-of select="@RequiresReplication"/></td>
  22.            <td><xsl:value-of select="@RequiresSetup"/></td>
  23.            <td><xsl:value-of select="@InterfaceSide"/></td>
  24.            <td><xsl:value-of select="@IPAddress"/></td>
  25.       </tr>
  26.       </xsl:for-each>
  27.     </table>
  28.    </body>
  29.   </html>
  30. </xsl:template>
  31. </xsl:stylesheet>
  32.  
Apr 7 '10 #12
GabeGGG
17
@jkmyoung
jkmyoung

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

Thanks,

Gabe
Apr 12 '10 #13
jkmyoung
2,057 Expert 2GB
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.
Apr 12 '10 #14
GabeGGG
17
@jkmyoung
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 Images
File Type: jpg EXAMPLE5.jpg (16.6 KB, 337 views)
Apr 12 '10 #15
jkmyoung
2,057 Expert 2GB
Sorry, this goes beyond my expertise. I would like to help; however, these nuances are quite obscure, and it's hard to find people with similar working experience. Hope you can find what you're looking for.
Apr 13 '10 #16
GabeGGG
17
Jkmyoung

I'm now running version 3 of MSXML2 in "Replace" mode. Is this the version that you are running? Please see attachments?
Attached Images
File Type: jpg Example6.jpg (16.8 KB, 229 views)
File Type: jpg Example7.jpg (17.7 KB, 283 views)
Apr 13 '10 #17

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by gregmcmullinjr | last post: by
11 posts views Thread by Ebenezer | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.