xsl-list
[Top] [All Lists]

[xsl] How to Get Nested Nodes

2011-12-22 02:29:38
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(_at_)com(_dot_)com</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(_at_)com(_dot_)com</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(_at_)com(_dot_)com</emailAddress>
   <status>Active</status>
  </contact>
  <contact>
   <id>4321</id>
   <name>David Vaughn</name>
   <emailAddress>dv(_at_)com(_dot_)com</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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>