2011-01-24 68 views
1

我目前正在使用以下XSLT代碼,以成功/動態放置Facebook,linkedin和twitter圖標,並使用條件(如果XLM中的成員數據顯示他們有臉書(即如果Facebook元素是非空的)。如何將XSLT轉換爲InDesign CS5輸出(不輸出到html)以自動將相應的/唯一的Facebook URL分配給圖像?由於將URL超鏈接動態分配給XSLT中的圖像以放入InDesign CS5

這裏是XSLT代碼(我得給了Facebook,微博的圖標圖像和鏈接中,如果存在一個URL):

<?xml version="1.0"?><!DOCTYPE xsl:stylesheet [ 
<!ENTITY nbsp "&#160;"> 
<!ENTITY mdash "&#8212;">]> 

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

<xsl:template match="/"> 
<memberdata> 
<xsl:for-each select="memberdata/memberinfo"> 
<xsl:sort select="SortKey"/> 

<memberdata> 


<xsl:if test="twitter[.!='']"> 
<twitter><xsl:attribute name="href">file://logos/twitter.jpg</xsl:attribute></twitter> 
</xsl:if> 

<xsl:if test="facebook[.!='']"> 
<facebook><xsl:attribute name="href">file://logos/facebook.jpg</xsl:attribute></facebook> 
</xsl:if> 

<xsl:if test="linkedin[.!='']"> 
<linkedin><xsl:attribute name="href">file://logos/linkedin.jpg</xsl:attribute></linkedin> 
</xsl:if> 


</memberdata> 

</xsl:for-each> 

</memberdata> 

</xsl:template> 
<xsl:template match="twitter"> 
</xsl:template> 
<xsl:template match="facebook"> 
</xsl:template> 
<xsl:template match="linkedin"> 
</xsl:template> 

</xsl:stylesheet> 

和XLM:

<?xml version="1.0"?> 
<memberdata xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"> 
<memberinfo> 

<email>[email protected]</email> 
<facebook>http://www.URL1a.com</facebook> 
<linkedin>http://www.URL1b.com</linkedin> 
<vimeo>http://www.URL1c.com</vimeo> 

</memberinfo> 
<memberinfo> 

<email>[email protected]</email> 
<facebook>http://www.URL2a.com</facebook> 
<linkedin>http://www.URL2b.com</linkedin> 
<vimeo>http://www.URL2c.com</vimeo> 

</memberinfo> 
</memberdata> 
+0

請注意,儘管facebook圖片是相同的,但每個會員數據可能包含XLM facebook元素中的不同/唯一URL,即www.facebook.com/abc,www.facebook.com/xyz等。目標是讓facebook圖標出現(它已經可以正常工作),但它也會顯示相應的URL,分配給它的www.facebook.com/abc等,這樣當我們導出爲PDF時,它就是一個實時鏈接。謝謝。 – Tom 2011-01-24 09:21:03

回答

0

你不需要if你的元素 - 這將處理模板您:

<xsl:template match="twitter[.!='']"> 
    <twitter> 
     <xsl:attribute name="href">file://logos/twitter.jpg</xsl:attribute> 
    </twitter> 
</xsl:template> 

<xsl:template match="facebook[.!='']"> 
    <facebook> 
     <xsl:attribute name="href">file://logos/facebook.jpg</xsl:attribute> 
    </facebook> 
</xsl:template> 

<xsl:template match="linkedin[.!='']"> 
    <linkedin> 
     <xsl:attribute name="href">file://logos/linkedin.jpg</xsl:attribute> 
    </linkedin> 
</xsl:template> 

也許您可以爲您的示例x​​ml添加所需的輸出...不清楚<email />元素會發生什麼情況。