2013-11-18 3 views
1
<?xml version="1.0" encoding="utf-8" ?> 
<?xml-stylesheet type="text/xsl" href="emails-selection.xsl" ?> 
<emails> 
    <email> 
     <from><![CDATA[Monique Stavinsky <[email protected]>]]></from> 
     <to><![CDATA[Peter Brown <[email protected]>]]></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 <[email protected]>]]></from> 
     <to><![CDATA[Peter Brown <[email protected]>]]></to> 
     <cc><![CDATA[Andrew Wozniak <[email protected]>]]></cc> 
     <cc><![CDATA[Dorothy May <[email protected]>]]></cc> 
     <cc><![CDATA[Peter Brown <[email protected]>]]></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 <[email protected]>]]></from> 
     <to><![CDATA[SHERATON Krakow <[email protected]>]]></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 <[email protected]>]]></from> 
     <to><![CDATA[Peter Brown <[email protected]>]]></to> 
     <to><![CDATA[Dorothy May <[email protected]>]]></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 <[email protected]>]]></from> 
     <to><![CDATA[Andrew Wozniak <[email protected]>]]></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

<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> 

как отображать письма, отправленные в феврале?

+1

могли бы вы предоставить входной файл XML? Кроме того, в конце вашего вопроса, похоже, есть мусор персонажа. Не могли бы вы взглянуть? –

ответ

0

Как отобразить письма, отправленные в феврале?

Поскольку ваши date элементы все, кажется, имеют последовательный формат гггг-мм-дд, это довольно легко выбрать соответствующие те, используя предикат:

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

@ user2969012 тот же принцип, но другой предикат, вам нужны элементы электронной почты, такие как 'contains (to, 'Andrew Wozniak')'. –

+0

thx много, он работает select = "/ emails/email [(содержит,« Andrew Wozniak »)) или (содержит (cc,« Andrew Wozniak »))]" – user2969012

Смежные вопросы