<?xml version="1.0" encoding="utf-8"?>

<xslt:stylesheet version="1.0"
				xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
	xmlns:word="http://schemas.microsoft.com/office/word/2003/wordml"
	xmlns:o="urn:schemas-microsoft-com:office:office" 
	xmlns:lw="http://www.linkwerk.com/namespaces/xslt/misc" 
				>

<!-- © 2005 Stefan Mintert 
	 This is copyrighted material. Please read
	 http://www.linkwerk.com/pub/xml/invitation/licence.txt
	 
	 The purpose of this XSLT style sheet is described online
	 at http://www.linkwerk.com/pub/xml/invitation/.

	Legal notice: 
	If you want to use my XSLT script, please read the 
	Office 2003 XML Reference Schema Patent License at
	http://www.microsoft.com/mscorp/ip/format/xmlpatentlicense.asp
	While I don't call my piece of code a product, I have to display the following note:

	"This product may incorporate intellectual property owned by Microsoft Corporation. 
	The terms and conditions upon which Microsoft is licensing such intellectual 
	property may be found at http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp"

-->


<xslt:output 
	method="xml"
	encoding="utf-8"
        />

<!-- ====================================================== -->
<!-- Template for root element 'invitation' -->

<xslt:template match="invitation">
	<?mso-application progid="Word.Document"?>
	<word:wordDocument xml:space="preserve">
		<o:DocumentProperties>
		    <o:Title>Invitation to Birthday Party</o:Title>
		    <o:Author>invitation2wordml.xslt by Stefan Mintert, Linkwerk.com</o:Author>
		</o:DocumentProperties>
		<word:docPr>
			<word:view word:val="print"/>
			<word:zoom word:percent="80"/>
		</word:docPr>
	
		<word:styles>
			<!-- ========================================= -->
			<!-- Paragraph Styles                          -->
			<!-- ========================================= -->
			<word:style word:type="paragraph" word:styleId="event" word:default="off">
				<word:basedOn  word:val="StandardPara"/> 
				<word:name word:val="Event"/>
				<word:pPr>
					<word:jc  word:val="center"/>
					<word:shd word:val="clear" 
						   word:color="auto" word:fill="66BB66"/>
					
					<word:spacing 	word:before="100" 
								word:before-autospacing="off" 
								word:after="300" 
								word:after-autospacing="off"/>
				</word:pPr>
				<word:rPr>
					<word:b/>
					<word:shadow word:val="on"/>
					<word:sz word:val="72"/>
					<word:color word:val="ffffff"/>
				</word:rPr>
			</word:style>	
			<word:style word:type="paragraph" word:styleId="meta" word:default="off">
				<word:basedOn  word:val="StandardPara"/> 
				<word:name word:val="Meta"/>
				<word:rPr>
				</word:rPr>
			</word:style>	
			<word:style word:type="paragraph" word:styleId="footer" word:default="off">
				<word:basedOn  word:val="StandardPara"/> 
				<word:name word:val="Footer"/>
				<word:pPr>
					<word:spacing 	word:before="1000" 
								word:before-autospacing="off" 
								word:after="300" 
								word:after-autospacing="off"/>
				</word:pPr>
				<word:rPr>
					<word:sz word:val="18"/>
				</word:rPr>
			</word:style>	
			<word:style word:type="paragraph" word:styleId="" word:default="off">
				<word:basedOn  word:val="StandardPara"/> 
				<word:name word:val=""/>
				<word:pPr>
				</word:pPr>
				<word:rPr>
				</word:rPr>
			</word:style>	
			<!-- Default Paragraph Style                          -->
			<word:style word:type="paragraph" word:styleId="StandardPara" word:default="on">
				<word:name word:val="StandardPara"/>
				<word:pPr>
				</word:pPr>
				<word:rPr>
					<word:rFonts word:ascii="Comic Sans MS" word:h-ansi="Comic Sans MS" word:cs="Comic Sans MS"/>
					<word:sz word:val="36"/>
				</word:rPr>
			</word:style>	
			<!-- ========================================= -->
			<!-- Character Styles                          -->
			<!-- ========================================= -->
			<word:style word:type="character" word:default="off" word:styleId="location">
				<word:name word:val="location"/>
				<word:rPr><word:b/><word:color word:val="ff0000"/></word:rPr>
			</word:style>
			<word:style word:type="character" word:default="off" word:styleId="date">
				<word:name word:val="Date"/>
				<word:rPr><word:b/><word:color word:val="ff0000"/></word:rPr>
			</word:style>
			<word:style word:type="character" word:default="off" word:styleId="time">
				<word:name word:val="Time"/>
				<word:rPr><word:b/><word:color word:val="ff0000"/></word:rPr>
			</word:style>
			<word:style word:type="character" word:styleId="Hyperlink">
			    <word:name word:val="Hyperlink" /> 
			        <word:basedOn word:val="DefaultParagraphFont" /> 
			    <!-- <word:rsid word:val="365462" /> -->
			    <word:rPr>
			        <word:color word:val="0000FF" /> 
			        <word:u word:val="single" /> 
			    </word:rPr>
			</word:style>
		</word:styles>
	
	  <word:body>
	
		<xslt:apply-templates select="event"/>
	    <word:p>
	        <word:pPr>
	            <word:pStyle word:val="meta"/>
	        </word:pPr>
	        <word:r>
	            <word:t>I'd like to invite you to come to </word:t>
	        </word:r>
		
			<xslt:apply-templates select="location"/>
	        <word:r>
	            <word:t>. </word:t>
	        </word:r>

	        
	        <word:r>
	            <word:t>The event takes place on </word:t>
	        </word:r>
	
	
			<xslt:apply-templates select="date"/>

	        <word:r>
	            <word:t> at </word:t>
	        </word:r>

			<xslt:apply-templates select="time"/>
	        <word:r>
	            <word:t>. </word:t>
	        </word:r>
	    </word:p>

		<xslt:apply-templates select="description"/>

		<xslt:apply-templates select="dresscode"/>

	    <word:p>
	        <word:pPr>
	            <word:pStyle word:val="footer"/>
	        </word:pPr>
	        <word:r>
	            <word:t>Generated from XML with invitation2html.xslt. Copyright &#169; </word:t>
		   	</word:r>
			    <word:hlink word:dest="http://www.mintert.com/">
			        <word:r>
			            <word:rPr>
			                <word:rStyle word:val="Hyperlink" /> 
			            </word:rPr>
			            <word:t>Stefan Mintert</word:t> 
			        </word:r>
			     </word:hlink>
		        <word:r>
		            <word:t>, available at </word:t>
			   	</word:r>
			    <word:hlink word:dest="http://www.linkwerk.com/">
			        <word:r>
			            <word:rPr>
			                <word:rStyle word:val="Hyperlink" /> 
			            </word:rPr>
			            <word:t>Linkwerk.com</word:t> 
			        </word:r>
			     </word:hlink>
   	    </word:p>

	  </word:body>
	
	</word:wordDocument>


</xslt:template>
<!-- ====================================================== -->




<!-- ====================================================== -->
<!-- Template for element type 'event' -->

<xslt:template match="event">
    <word:p>
        <word:pPr>
            <word:pStyle word:val="event"/>
        </word:pPr>
        <word:r>
	        <word:rPr>
	            <word:sz word:val="24"/>
	        </word:rPr>
            <word:br/>
        </word:r>
        <word:r>
            <word:t><xslt:apply-templates/></word:t>
            <word:br/>
        </word:r>
    </word:p>
</xslt:template>
<!-- ====================================================== -->




<!-- ====================================================== -->
<!-- Template for some inline element types -->
<xslt:template match="location | date | time">
	<word:r>
		<word:rPr><word:rStyle word:val="{local-name()}"/>
			<word:t><xslt:apply-templates/></word:t>
		</word:rPr>
	</word:r>		
</xslt:template>
<!-- ====================================================== -->



<!-- ====================================================== -->
<!-- Template for element type 'description' -->

<xslt:template match="description">
    <word:p>
        <word:pPr>
            <word:pStyle word:val="description"/>
        </word:pPr>
        <word:r>
        	<word:rPr>
        		<word:b/>
        	</word:rPr>
            <word:t><word:br/>What's up?</word:t>
        </word:r>
    </word:p>
	<xslt:apply-templates/>
</xslt:template>
<!-- ====================================================== -->


<!-- ====================================================== -->
<!-- Template for element type 'para' -->

<xslt:template match="para">
    <word:p>
        <word:pPr>
            <word:pStyle word:val="description"/>
        </word:pPr>
        <xslt:apply-templates select="text()|*"/>
	    <word:r>
			<word:t><word:br/></word:t>
		</word:r>
    </word:p>
</xslt:template>
<!-- ====================================================== -->



<!-- ====================================================== -->
<!-- Template for text within 'para' -->

<xslt:template match="para/text()">
    <word:r>
		<word:t><!--<xslt:value-of select="normalize-space(.)"/>-->
		<xslt:call-template name="lw:normalize-space"/></word:t>
	</word:r>
</xslt:template>
<!-- ====================================================== -->


<!-- ====================================================== -->
<!-- Template for element type 'emph' -->

<xslt:template match="text()">
    <xslt:value-of select="normalize-space(.)"/>
</xslt:template>
<!-- ====================================================== -->



<!-- ====================================================== -->
<!-- Template for element type 'emph' within 'para' -->
<xslt:template match="para/emph">
    <word:r>
        <word:rPr>
            <word:i/>
        </word:rPr>
		<word:t><xslt:value-of select="."/></word:t>
	</word:r>
</xslt:template>
<!-- ====================================================== -->
            

<!-- ====================================================== -->
<!-- Template for element type 'dresscode' -->
<xslt:template match="dresscode">
	    <word:p>
	        <word:pPr>
	            <word:pStyle word:val="dresscode"/>
	        </word:pPr>
	        <word:r>
	        	<word:rPr>
	        		<word:b/>
	        	</word:rPr>
	            <word:t>What to wear?<word:br/></word:t>
	        </word:r>

		    <word:r>
				<word:t><xslt:apply-templates/></word:t>
			</word:r>			
	    </word:p>
</xslt:template>
<!-- ====================================================== -->



<xslt:template name="lw:normalize-space">
	<xslt:param name="Node-Set" select="."/>
       
	<xslt:variable name="Result-Str">

		<xslt:for-each select="$Node-Set">
		
			<!-- add a delimiter at both sides of the string, then normalize -->
			<xslt:variable name="Norm-Str" select="normalize-space(concat('!', ., '!'))"/>
			
			<!-- remove the delimiter before returning the result -->
			<xslt:value-of select="substring($Norm-Str, 2, string-length($Norm-Str)-2)"/>
		
		</xslt:for-each>
	</xslt:variable>

	<xslt:value-of select="$Result-Str"/>
</xslt:template>


</xslt:stylesheet>
