[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

sub element selection

Subject: sub element selection
From: Pete.Gomez@xxxxxxxxxxxxx
Date: Tue, 16 Apr 2002 12:39:02 -0400
pete gomez
Hi.  I'm new to XSL and have what I think is a basic question.  I'm trying
to do the conversion below with the stylesheet at the bottom of the email.
I want to use the  makeProperty template in my solution since many of the
easier XSL things I've coded call it.
I'm having trouble figuring out how to get the value of CommunicationType
and then compare it to a string (or should it be a variable?).  If you see
an obviously easier way to do it (xsl:when?  xsl:for-each?) please let me
know.

BTW - I have been checking through the various tutorials and archives
listed.  I think part of the problem with being new is I  don't know
exactly what search terms to use to get what I want.

Thanks
Pete

-------------  XML input snippet ----------------

    <CustomerContact>
     <ContactType>Person</ContactType>
     <PersonContact>
          <Communication>
               <CommunicationType>DAYPHONE</CommunicationType>
               <CommunicationNumber>800-5551212</CommunicationNumber>
          </Communication>
          <Communication>
               <CommunicationType>EMAIL</CommunicationType>
               <CommunicationNumber>mickey@xxxxxxxxxx</CommunicationNumber>
          </Communication>
     </PersonContact>
    </CustomerContact>

------------- desired XML output ----------------
(note: DAYPHONE, above, maps to HOMEPHONE and EMAIL maps to DRV1_EMAIL)

<property name="HOMEPHONE" value="800-5551212"/>
<property name="DRV1_EMAIL" value="mickey@xxxxxxxxxx"/>

------------- stylesheet snippet ----------------
<xsl:template match="Communication">
     <xsl:apply-templates select="CommunicationType"/>
</xsl:template>

<xsl:template match="CommunicationType">
     <xsl:if test="....?..... = 'DAYPHONE'">
          <xsl:call-template name="makeProperty">
               <xsl:with-param name="name">HOMEPHONE</xsl:with-param>
               <xsl:with-param name="value" select="....?......" />  <!-- i want to get CommunicationNumber here -->
          </xsl:call-template>
     </xsl:if>
     <xsl:if test="....?..... = 'EMAIL'">
          <xsl:call-template name="makeProperty">
               <xsl:with-param name="name">DRV1_EMAIL</xsl:with-param>
               <xsl:with-param name="value" select="....?...." />   <!-- i want to get CommunicationNumber here -->
          </xsl:call-template>
     </xsl:if>
</xsl:template>

<xsl:template name="makeProperty">
    <xsl:param name="name"/>
    <xsl:param name="value"/>
     <property>
          <xsl:attribute name="name">
               <xsl:value-of select="$name" />
          </xsl:attribute>
          <xsl:attribute name="value">
               <xsl:value-of select="$value" />
          </xsl:attribute>
     </property>
</xsl:template>




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.