xsl选择中的函数子字符串

时间:2013-11-18 11:12:48

标签: xml date xslt substring selection

   <?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="emails-selection.xsl" ?>
 <emails>
    <email>
        <from><![CDATA[Monique Stavinsky <monique@upc.com>]]></from>
        <to><![CDATA[Peter Brown <peter.brown@gmail.com>]]></to>
        <subject>My love</subject>
        <date>2010-12-22</date>
        <body><![CDATA[To my one and only love,

I’ve been waiting for you for so long, and now that you are here with me, I will never ever let you go. We both know that life is not always fair. We know that there will come a time when we have to face trials in our relationship, but we will overcome because our love will see us through. They say promises are made to broken, but I say promises is meant to be for as long as we believe in the power of love... I know in my heart you believe it too. I am so thankful and so very happy that I have found my destiny in you.

You are my happiness, a very special blessing God has given to me. I’m so excited spending my whole life with someone that I truly love and care about, spending each special day with all the love in our heart of hearts. I love you so much and will always love until forever. That's a promise that I’ll surely going to keep forever in my heart.

Monique ]]></body>
    </email>
    <email status="important">
        <from><![CDATA[MEGASTORE <megastore@bookshop.co.uk>]]></from>
        <to><![CDATA[Peter Brown <peter.brown@gmail.com>]]></to>
        <cc><![CDATA[Andrew Wozniak <awozniak@abc.com>]]></cc>
        <cc><![CDATA[Dorothy May <mayd@yellowbook.com>]]></cc>
        <cc><![CDATA[Peter Brown <peter.brown@gmail.com>]]></cc>
        <subject>Special offer</subject>
        <date>2010-02-17</date>
        <body><![CDATA[Good news! Subscribers to our email newsletter can take advantage of fantastic price savings in our January sale. I've attached a pdf file that gives full details, or alternatively just click on the link below. You can order over the web or by email - our customer service staff are standing by. Looking forward to hearing from you soon.]]></body>
    </email>
    <email>
        <from><![CDATA[Peter Brown <peter.brown@gmail.com>]]></from>
        <to><![CDATA[SHERATON Krakow <office@sheraton.krakow.pl>]]></to>
        <subject>Hotel reservation</subject>
        <date>2010-09-02</date>
        <body><![CDATA[I would like to reserve a room for 3 nights 1-3 December inclusive. Could you alo confirm the corporate price I was quoted of PLN192.00 including breakfast buffet?]]></body>
    </email>
    <email>
        <from><![CDATA[ABC Electronic <office@abc-electronics.com>]]></from>
        <to><![CDATA[Peter Brown <peter.brown@gmail.com>]]></to>
        <to><![CDATA[Dorothy May <mayd@yellowbook.com>]]></to>
        <subject>Welcome to our Team!</subject>
        <date>2010-05-29</date>
        <body><![CDATA[Dear,

Welcome to our Team!

It is a pleasure to welcome you to the staff of ABC Electronics. We are excited to have you join our team, and we hope that you will enjoy working with our company.

On the first Monday of each month we hold a special staff lunch to welcome any new employees. Please be sure to come next week to meet all of our senior staff and any other new staff members who have joined us this month. Angelina Swan will e-mail you with further details.

If you have any questions during your training period, please do not hesitate to contact me. You can reach me at my email address or on my office line at 340-2222.

Warm regards,
Jack]]></body>
    </email>
    <email status="important">
        <from><![CDATA[Peter Brown <peter.brown@gmail.com>]]></from>
        <to><![CDATA[Andrew Wozniak <awozniak@abc.com>]]></to>
        <subject>Meeting in London</subject>
        <date>2010-02-01</date>
        <body><![CDATA[Hi Paul,

Great idea to hold the SM in London. I'm looking forward to it. Sept 23-24 is fine with me; the German team will present our market study (should be finished by then).

See you
Peter]]></body>
    </email>
    <!--
        Bibliography:
        Paul Emmerson, Email English, MACMILLIAN 2010
        Rebecca Chapman, English for Emails, Cornelsen Verlag GmbH & Co OHG, Berlin 2003
        Kirsten Wachter, Emailing in English, Cornelsen Verlag GmbH & Co OHG, Berlin
    -->
</emails>

    

    <xsl:template match="/">
        <html>
            <head>
                <title>Email box</title>
                <style type="text/css">
                    .emailsubject {background-color:fuchsia; font-size:x-large; }
                    .emailbody {font-family:sans-serif; font-size:11pt}
                    .emailsender {font-style:italic}
                </style>
            </head>
            <body>
                <h1>Email box</h1>
                <h3>elements selection</h3>
                <xsl:apply-templates select="substring(/emails/email/date,6,2)" />
            </body>
        </html>
    </xsl:template>

    <xsl:template match="email">
        <p class="emailsubject">
            <xsl:number value="position()" format="1. " />
            <xsl:value-of select="subject"/>
        </p>
        <p class="emailsender"><text>from: </text><xsl:value-of select="from"/><text>, </text><xsl:value-of select="date"/></p>
        <p class="emailbody"><xsl:value-of select="body"/></p>
    </xsl:template>

</xsl:stylesheet>

如何显示2月发送的信件?

1 个答案:

答案 0 :(得分:0)

  

如何显示2月份发送的信件?

由于您的date元素似乎都具有一致的yyyy-mm-dd格式,因此使用谓词选择相关元素非常容易:

<xsl:apply-templates select="/emails/email[substring(date, 6, 2) = '02']" />