[xsl] How to Get Nested Nodes

Subject: [xsl] How to Get Nested Nodes
From: Jeffry Proctor <jpgmt@xxxxxxxxxxxxx>
Date: Thu, 22 Dec 2011 00:29:26 -0800 (PST)
List of Contacts from: feed/entry/content/Contacts
 
Ultimately I would like
to use a few XSLT's to extract different datasets, my C# 
component, will just
have a few functions, be somewhat xml, xslt agnostic, 
getting the function's
corresponding XSLT from an xml (think ini file) to 
transfrom and return the
datasets from the resulting xml; I'm choosing this over 
a static
looping/switch/case node= xpath walking, if anything changes I'd have 
to
re-code, I'd rather just update the offending xslt(s) and push that out to
the client, no install or dll issues, but I digress...
 
I'm trying to get a
list of contacts from the following xml source
 
<?xml version="1.0"
encoding="utf-8"?>
<?xml-stylesheet type="text/xsl"
href="_XSLT_Contacts_vb2.xsl"? >
<feed>
<title type="text">Contacts For
Jeffry</title>
<updated>2011-12-21T16:23:21.0989</updated>
<entry>
   
<title>contact: xray220</title> 
   
<updated>2009-11-19T14:49:23.203Z</updated> 
    <content
type="application/vnd.zaner+xml">
        <Contact id="1234" 
         
xmlns="http://sites.google.com/site/jeffryproctor/";>
           
<status>Active</status>
            <emailAddress>jp@xxxxxxx</emailAddress>
            <name>Jeffry Proctor</name>
        </Contact>
    </content>
</entry>
<entry>
    <title>contact: xray221</title> 
   
<updated>2009-11-19T14:49:23.203Z</updated> 
    <content
type="application/vnd.zaner+xml">
        <Contact id="4321"       
         
xmlns="http://sites.google.com/site/jeffryproctor/";>
     
<status>Active</status>
            <emailAddress>dv@xxxxxxx</emailAddress>
            <name>David Vaughn</name>
        </Contact>
    </content>
</entry>
</feed>
I'd like the resulting xml to look like this
 
<?xml
version="1.0" encoding="UTF-8"?>
<ContactList
 xmlns:msxml="urn:schemas-microsoft-com:xslt"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
 xmlns:xsd="http://www.w3.org/2001/XMLSchema";
 xmlns="http://www.w3.org/2005/Atom>
 <Contacts>
  <contact>
   <id>1234</id>
   <name>Jeffry Proctor</name>
   <emailAddress>jp@xxxxxxx</emailAddress>
  
<status>Active</status>
  </contact>
  <contact>
   <id>4321</id>
  
<name>David Vaughn</name>
   <emailAddress>dv@xxxxxxx</emailAddress>
  
<status>Active</status>
  </contact>
 </Contacts>
</ContactList>
 
Here is my
attempt/failure xslt, which I can easily abandon in favor or a better 
layout
& technique.
 
<!--<?xml version="1.0"  encoding="UTF-8"?>-->
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   
xmlns:msxml="urn:schemas-microsoft-com:xslt"    
   
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; >
    <xsl:template name="main"
match="feed"
        xmlns="http://www.w3.org/2005/Atom";>
       
<ContactList>
            <contacts>                
               
<xsl:call-template name="contact"/>                
            </contacts>
        </ContactList>        
    </xsl:template>
    <xsl:template
name="contact" match="entry">
        <xsl:for-each select="content/Contact">
            <Contact>
                <id>
                    <xsl:value-of
select="@id"/>
                </id>
                <name>
                    <xsl:value-of select="name"/>
                </name>
                <emailAddress>
                    <xsl:value-of
select="emailAddress"/>
                </emailAddress>
               
<status>
                    <xsl:value-of select="status"/>
               
</status>
            </Contact>
        </xsl:for-each >
   
</xsl:template>    
</xsl:stylesheet>
 
Thanks in advance

JeffPGMT

Current Thread