Thread: counting in XSL
View Single Post
  #5 (permalink)  
Old March 28th, 2006, 06:59 PM
gezi gezi is offline
Registered User
 
Join Date: Mar 2006
Location: Sunland, California, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

I really appreciate that you want to help me out there, because this
is really something that I should learn and know.

I made a little excerpt of my address file with only two entries,
the first one maps great to a vcard, but the second makes quite some
problems.

Here I have the elements BB and NO that I would like to get all into
the NOTE element of the vCard.

In my included xsl file below I now only look for the last NO and the
other unknown elements are just bypassed.

I have long years of programming on my back, everything assembler to
C++, but with all this I can't seem to find a way to handle this little
problem, and I am so thick-headed now that I want to solve it with
xsl instead of just writing a C program <grin>

Thanks
Gunter


==== file allad.xml ===============================================

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="allad.xsl"?>

<ALLAD>
  <MARK>
    <LETTER>====A====</LETTER>

    <ADD>
      <CO>Able Avionics</CO>
      <BS>16644 Roscoe Blvd.</BS>
      <BC>Van Nuys</BC>
      <BT>California</BT>
      <BZ>91406</BZ>
      <BP>(818) 779-0265</BP>
    </ADD>

  </MARK>

  <MARK>
    <LETTER>====C====</LETTER>

    <ADD>
      <CO>CompuServe</CO>
      <BP>(800) 848-8990</BP>
      <BB>(800) 346-3147</BB>
      <BB>(909) 865-0553</BB>
      <BB>(818) 988-9791</BB>
      <NO>112465,3713 User Number</NO>
      <NO>port#: 4144</NO>
    </ADD>

  </MARK>

</ALLAD>


==== file allad.xsl ================================================

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
<HTML><BODY><pre>
<xsl:apply-templates/>
</pre></BODY></HTML>
</xsl:template>

<xsl:template match="MARK"><xsl:apply-templates select="ADD"/></xsl:template>

<xsl:template match="ADD">
BEGIN:VCARD
VERSION:2.1
<xsl:choose>
<xsl:when test="FN or LN">N:<xsl:value-of select="LN"/>;<xsl:value-of select="FN"/>;<xsl:value-of select="MN"/>;<xsl:value-of select="TI"/>;
FN:<xsl:value-of select="TI"/> <xsl:if test="TI">#160;</xsl:if> <xsl:value-of select="FN"/> <xsl:if test="FN">#160;</xsl:if> <xsl:value-of select="MN"/> <xsl:if test="MN">#160;</xsl:if> <xsl:value-of select="LN"/> #160;
<xsl:if test="CO">ORG:<xsl:value-of select="CO"/>#160;<xsl:value-of select="DS"/></xsl:if>
</xsl:when>
<xsl:otherwise>N:<xsl:value-of select="CO"/>;<xsl:value-of select="DS"/>;;;
FN:<xsl:value-of select="CO"/> <xsl:value-of select="DS"/></xsl:otherwise>
</xsl:choose>

<xsl:apply-templates select="HS|BS|PH|VM|FX|MB|WB|PG|EM|BP|BF|BX|WW|BB| CT|NO"/>
END:VCARD
</xsl:template>


<xsl:template match="HS">
ADR;HOME:<xsl:value-of select="../HM"/>;;<xsl:value-of select="."/>;<xsl:value-of select="../HC"/>;<xsl:value-of select="../HT"/>;<xsl:value-of select="../HZ"/>;<xsl:value-of select="../H0"/>
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:<xsl:value-of select="."/>=0D=0A<xsl:value-of select="../HC"/>, <xsl:value-of select="../HT"/> <xsl:value-of select="../HZ"/>=0D=0A<xsl:value-of select="../HO"/>
</xsl:template>

<xsl:template match="BS">
ADR;WORK:<xsl:value-of select="../BM"/>;<xsl:value-of select="../MS"/>;<xsl:value-of select="."/>;<xsl:value-of select="../BC"/>;<xsl:value-of select="../BT"/>;<xsl:value-of select="../BZ"/>;<xsl:value-of select="../B0"/>
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:<xsl:value-of select="../MS"/>=0D=0A<xsl:value-of select="."/>=0D=0A<xsl:value-of select="../BC"/>, <xsl:value-of select="../BT"/> <xsl:value-of select="../BZ"/>=0D=0A<xsl:value-of select="../BO"/>
</xsl:template>

<xsl:template match="JT">
TITLE:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="BP">
TEL;WORK;VOICE:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="BP2">
TEL;WORK;VOICE:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="PH">
TEL;HOME;VOICE:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="MB">
TEL;CELL;VOICE:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="BF">
TEL;WORK;FAX:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="FX">
TEL;HOME;FAX:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="WW">
URL;WORK:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="BD">
BDAY:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="EM">
EMAIL;PREF;INTERNET:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="NO">
NOTE;ENCODING=QUOTED-PRINTABLE:<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="MS|OF|VM|WB|PG|BX|BB|CT">
</xsl:template>

</xsl:stylesheet>

================================================== ====================