又是广告转换程序

星期四 天气:晴
 
今天上午集团组织体检了.
 
这些天做的,留个念想.
先上xml结构,这个是从数据获取的两个DataSet合并生成的.
 
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="newwindow.xslt"?>
<NewDataSet>
 <Table>
  <iPositionID>1</iPositionID>
  <cImageUrl>/img/1.jpg</cImageUrl>
  <cDefaultText>最新广告</cDefaultText>
  <iCycle>0.1</iCycle>
  <iHeightSize>600</iHeightSize>
  <iWidthSize>800</iWidthSize>
  <!--0随机,1轮循-->
  <iDisplayType>1</iDisplayType>
  <gAttach>WV0IHZlcnNpb249IKbWF0Y2g9Iip8dGV4dCgpIjlZXQ+DQoNCiAg</gAttach>
 </Table>
  
 <Table>
  <iADItemID>1</iADItemID>
  <cFileName>金镶玉2.jpg</cFileName>
  <cFileType>image/jpg</cFileType>
  <cLink>/map.aspx</cLink>
  <cTitle>中llll国</cTitle>
 </Table>
 
 <Table>
  <iADItemID>3</iADItemID>
  <cFileUrl>/img/pic-test-003.gif</cFileUrl>
  <cFileType>image/jpg</cFileType>
  <cLink>/Login.aspx</cLink>
  <cTitle>中国</cTitle>
 </Table>
 
 <Table>
  <iADItemID>4</iADItemID>
  <cFileUrl>/img/1.swf</cFileUrl>
  <cFileType>application/x-shockwave-flash</cFileType>
  <cTitle>Flash1</cTitle>
 </Table>
 
 <Table>
  <iADItemID>5</iADItemID>
  <cFileUrl>/img/4.swf</cFileUrl>
  <cFileType>application/x-shockwave-flash</cFileType>
  <cLink></cLink>
  <cTitle>Flash2</cTitle>
 </Table>
 
 <Table>
  <iADItemID>6</iADItemID>  
  <cLink>/map.aspx</cLink>
  <cTitle>Flash2</cTitle>
 </Table>
 <!---->
</NewDataSet>

这几个是转换程序,个个都有一身好武艺.

Comm.xslt

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:dyens="http://localhost/">
 
 <msxsl:script implements-prefix="dyens" language="javascript">
 <![CDATA[
  function GetRandomInt(iNum)
  {
   return Math.floor(Math.random() * (iNum + 1) );
  }
 ]]>
 </msxsl:script>
 <!--
 <msxsl:script implements-prefix="dyens" language="CSharp">
 <![CDATA[
  public int GetRandomInt_CSharp(iNum)
  {
   return new Random().Next(0,iNum);
  }
 ]]>
 </msxsl:script>
 -->
</xsl:stylesheet>

SimpleText.xslt
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:dyens="http://localhost/">
  
 <xsl:import href="Comm.xslt"/>
 <xsl:output method="html" />
 
 <!--广告位-->
 <xsl:template match="/NewDataSet/Table[iPositionID]">
  <!--<textarea cols="500" rows="35">-->
  <!--DIV开始-->
  <xsl:element name="div">   
   <xsl:attribute name="style">
    <xsl:value-of select="concat('position:relative;overflow:hidden;top:0px;left:0px;width:', iWidthSize, 'px;height:', iHeightSize, 'px')" />
   </xsl:attribute>
   <a id="labItem_{iPositionID}"> </a>     
   
   <xsl:variable name="_ADItems">
    <xsl:call-template name="GetADItems" />
   </xsl:variable>
   
    <SCRIPT LANGUAGE="JavaScript">
    <xsl:choose>    
    <xsl:when test="iDisplayType=1">
     <xsl:call-template name="GetRollScript">
      <xsl:with-param name="_iPositionID" select="iPositionID"></xsl:with-param>
      <xsl:with-param name="_ADItems" select="msxsl:node-set($_ADItems)"></xsl:with-param>
      <xsl:with-param name="_iCycle" select="iCycle" />
     </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
     <xsl:call-template name="GetRandomScript">
      <xsl:with-param name="_iPositionID" select="iPositionID"></xsl:with-param>
      <xsl:with-param name="_ADItems" select="msxsl:node-set($_ADItems)"></xsl:with-param>
     </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="$_ADItems=''">
     <xsl:call-template name="GetDefaultScript">
      <xsl:with-param name="_iPositionID" select="iPositionID" />
      <xsl:with-param name="_defaultText" select="cDefaultText" />
     </xsl:call-template>
    </xsl:if>
    </SCRIPT>
  </xsl:element>
  <!--DIV块结束-->
  <!--</textarea>-->
 </xsl:template>
 
 <!--获取指定广告位内广告项-->
 <xsl:template name="GetADItems">
  <xsl:for-each select="/NewDataSet/Table[not(iPositionID)]">
   <Item>
    <ADItemID><xsl:value-of select="iADItemID" /></ADItemID>
    <Text><xsl:value-of select="cTitle" /></Text>
    <Href><xsl:value-of select="cLink" /></Href>
   </Item>
  </xsl:for-each>
 </xsl:template>   
 
 <!--默认脚本-->
 <xsl:template name="GetDefaultScript">
  <xsl:param name="_iPositionID" />
  <xsl:param name="_defaultText" />    
  var o = document.getElementById("labItem_<xsl:value-of select="$_iPositionID" />");
  o.innerText = "<xsl:value-of select="$_defaultText" />";  
 </xsl:template> 
 
 <!--获取随机脚本-->
 <xsl:template name="GetRandomScript">
  <xsl:param name="_iPositionID" />
  <xsl:param name="_ADItems" />
  <xsl:if test="count($_ADItems/Item) > 0">
   <!--随机数0到广告数减1.-->
   <xsl:variable name="_i" select="dyens:GetRandomInt(count($_ADItems/Item)-1)"></xsl:variable>
   <xsl:variable name="_item" select="$_ADItems/Item[position()=$_i+1]" />   
   var o = document.getElementById("labItem_<xsl:value-of select="$_iPositionID" />");
   o.innerText = "<xsl:value-of select="$_item/Text" />";   
   <xsl:if test="$_item/Href and $_item/Href != ''">
   o.href = "/ADManager/ADManager.UI/ADControler.aspx?href=<xsl:value-of select="$_item/Href" />&amp;id=<xsl:value-of select="$_item/ADItemID" />";
   o.target = "_blank";
   </xsl:if>
  </xsl:if>  
 </xsl:template> 
 
 <!--获取轮循脚本-->
 <xsl:template name="GetRollScript">
  <xsl:param name="_iPositionID" />
  <xsl:param name="_ADItems" />
  <xsl:param name="_iCycle" />
  function ADItem(text, url)
  {
   this.Text = text;
   this.Url = url;
  }
  count_<xsl:value-of select="$_iPositionID" /> = 0;
  var _aditemCollection_<xsl:value-of select="$_iPositionID" /> = new Array();
  var _aditem;
  <xsl:for-each select="$_ADItems/Item">    
    <xsl:choose>
     <xsl:when test="Href=''">
  _aditem = new ADItem("<xsl:value-of select="Text" />");
     </xsl:when> 
     <xsl:otherwise>
  _aditem = new ADItem("<xsl:value-of select="Text" />", "/ADManager/ADManager.UI/ADControler.aspx?href=<xsl:value-of select="Href" />&amp;id=<xsl:value-of select="ADItemID" />")     
     </xsl:otherwise>     
    </xsl:choose>
  _aditemCollection_<xsl:value-of select="$_iPositionID" />.push(_aditem);    
  </xsl:for-each>
  Roll_<xsl:value-of select="$_iPositionID" />();
  function Roll_<xsl:value-of select="$_iPositionID" />()
  {  
   if(count_<xsl:value-of select="$_iPositionID" /> &gt;= _aditemCollection_<xsl:value-of select="$_iPositionID" />.length)
   {
    count_<xsl:value-of select="$_iPositionID" /> = 0;
   }
   var o = document.getElementById("labItem_<xsl:value-of select="$_iPositionID" />");
   o.innerText = _aditemCollection_<xsl:value-of select="$_iPositionID" />[count_<xsl:value-of select="$_iPositionID" />].Text;
   var items = _aditemCollection_<xsl:value-of select="$_iPositionID" />;
   var i = count_<xsl:value-of select="$_iPositionID" />;
   if(items[i].Url != null &amp;&amp; items[i].Url != "")
   {
    o.href = items[i].Url;
    o.target = "_blank";
   }
   else
   {
    o.removeAttribute("href");
    o.removeAttribute("target");
   }
   count_<xsl:value-of select="$_iPositionID" />++;
   setTimeout(Roll_<xsl:value-of select="$_iPositionID" />, <xsl:value-of select="$_iCycle" />*60000);
  }
 </xsl:template>
 
 <xsl:template match="text()"></xsl:template> 
</xsl:stylesheet> 

------------------------------SimpleImage.xslt-------------------------------------
<?xml version="1.0" encoding="GB2312" ?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:dyens="http://localhost/"
 exclude-result-prefixes="dyens msxsl xsl">
 
 <xsl:import href="Comm.xslt"/>
 <xsl:output method="html" /> 
 
 <xsl:template match="/">
  <xsl:call-template name="ADPosition"></xsl:call-template>
 </xsl:template>
 
 <!--广告位-->
 <xsl:template name="ADPosition">
  <xsl:variable name="_adPosition" select="/NewDataSet/Table[iPositionID]" />
  <!--DIV开始-->
  <xsl:element name="div">
   <!--链接与图片-->   
   <xsl:attribute name="style">
    <xsl:value-of select="concat('position:relative;overflow:hidden;width:', $_adPosition/iWidthSize, 'px;height:', $_adPosition/iHeightSize, 'px')" />
   </xsl:attribute>
   <a id="labItem_{$_adPosition/iPositionID}"><img id="imgItem_{$_adPosition/iPositionID}" border="0" /></a>   
   
   <script language="javascript">
    <xsl:variable name="_ADItems">
     <xsl:call-template name="GetADItems" />
    </xsl:variable>
    
    <xsl:choose>
     <xsl:when test="count(msxsl:node-set($_ADItems)/Item) > 0">
      <xsl:choose>    
       <xsl:when test="$_adPosition/iDisplayType=1">
        <xsl:call-template name="GetRollScript">
         <xsl:with-param name="_iPositionID" select="$_adPosition/iPositionID"></xsl:with-param>
         <xsl:with-param name="_ADItems" select="msxsl:node-set($_ADItems)"></xsl:with-param>
         <xsl:with-param name="_iCycle" select="$_adPosition/iCycle" />
        </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
        <xsl:call-template name="GetRandomScript">
         <xsl:with-param name="_iPositionID" select="$_adPosition/iPositionID"></xsl:with-param>
         <xsl:with-param name="_ADItems" select="msxsl:node-set($_ADItems)"></xsl:with-param>
        </xsl:call-template>
       </xsl:otherwise>
      </xsl:choose>
     </xsl:when>
     <xsl:otherwise>
      <xsl:call-template name="GetDefaultScript">
       <xsl:with-param name="_iPositionID" select="$_adPosition/iPositionID" />
       <xsl:with-param name="_defaultImage" select="$_adPosition/cImageUrl" />  
      </xsl:call-template>  
     </xsl:otherwise>
    </xsl:choose>
   </script>
  </xsl:element>  
 </xsl:template>
 
 <!--获取指定广告位内广告项-->
 <xsl:template name="GetADItems">
  <xsl:for-each select="/NewDataSet/Table[not(iPositionID) and cFileType='image/jpg']">
   <Item>
    <ADItemID><xsl:value-of select="iADItemID" /></ADItemID>
    <Image><xsl:choose>
      <xsl:when test="cFileUrl">
       <xsl:value-of select="cFileUrl" />
      </xsl:when>
      <xsl:otherwise>/ADManager/GetFile.aspx?type=2&amp;id=<xsl:value-of select="iADItemID" />
      </xsl:otherwise>
     </xsl:choose>
    </Image>
    <Text>
     <xsl:value-of select="cTitle" />
    </Text>
    <Href>
     <xsl:if test="cLink and cLink != ''">/ADManager/ADManager.UI/ADControler.aspx?href=<xsl:value-of select="cLink" />&amp;id=<xsl:value-of select="iADItemID" /></xsl:if>
    </Href>
   </Item>
  </xsl:for-each>
 </xsl:template>
 
 <!--默认脚本-->
 <xsl:template name="GetDefaultScript">
  <xsl:param name="_iPositionID" />
  <xsl:param name="_defaultImage" />  
  var oImg = document.getElementById("imgItem_<xsl:value-of select="$_iPositionID" />");
  oImg.src = "<xsl:value-of select="$_defaultImage" />";
 </xsl:template> 
 
 <!--获取轮循脚本-->
 <xsl:template name="GetRollScript">
  <xsl:param name="_iPositionID" />
  <xsl:param name="_ADItems" />
  <xsl:param name="_iCycle" />
  <![CDATA[
   function ADImage(src, url, title)
   {
    this.Src = src;
    this.Url = url;
    this.Title = title;
   }  
   
   function SimpleImage(items, lab, img, iCycle)
   {
    var i=0;
    function Roll()
    {  
     if(i >= items.length)
     {
      i=0;
     }
     var oHref = lab;//document.getElementById("labItem");
     var oImg = img;//document.getElementById("imgItem");  
     oImg.src = items[i].Src;
     if(items[i].Url != null && items[i].Url != "")
     {
      oHref.href = items[i].Url;
      oHref.target = "_blank";
      
     }
     else
     {
      oHref.removeAttribute("href");
      oHref.removeAttribute("target");   
     }
     
     if(items[i].Title != null)
     {
      oImg.title = items[i].Title;
     }
     else
     {
      oImg.removeAttribute("title");
     }
     
     i++;
     window.setTimeout(Roll, iCycle*60000);
    }
    this.Roll = Roll;
   }
  ]]>
  
  var _aditemCollection_<xsl:value-of select="$_iPositionID" /> = new Array();
  var _aditem;
  <xsl:for-each select="$_ADItems/Item">
  _aditem = new ADImage("<xsl:value-of select="Image" />", "<xsl:value-of select="Href" />", "<xsl:value-of select="Text" />");
  _aditemCollection_<xsl:value-of select="$_iPositionID" />.push(_aditem);    
  </xsl:for-each>
  
  new SimpleImage(_aditemCollection_<xsl:value-of select="$_iPositionID" />, document.getElementById("labItem_<xsl:value-of select="$_iPositionID" />"), document.getElementById("imgItem_<xsl:value-of select="$_iPositionID" />"), <xsl:value-of select="$_iCycle" />).Roll();
 </xsl:template>
 
 <!--获取随机脚本-->
 <xsl:template name="GetRandomScript">
 <xsl:param name="_iPositionID" />
  <xsl:param name="_ADItems" />   
   <xsl:variable name="_i" select="dyens:GetRandomInt(count($_ADItems/Item)-1)"></xsl:variable>
   <xsl:variable name="_item" select="$_ADItems/Item[position()=$_i+1]" />
    var oHref = document.getElementById("labItem_<xsl:value-of select="$_iPositionID" />");
    var oImg = document.getElementById("imgItem_<xsl:value-of select="$_iPositionID" />");
    oImg.src = "<xsl:value-of select="$_item/Image" />";
   <xsl:if test="$_item/Href and $_item/Href != ''">
    oHref.href = "<xsl:value-of select="$_item/Href" />";
    oHref.target = "_blank";
   </xsl:if>
   <xsl:if test="$_item/Text and $_item/Text != ''">
    oImg.title = "<xsl:value-of select="$_item/Text" />";    
   </xsl:if>
 </xsl:template>
</xsl:stylesheet> 
------------------------------------SimpleFlash.xslt------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:dyens="http://localhost/"
 exclude-result-prefixes="dyens msxsl xsl">
 
 <xsl:import href="Comm.xslt"/>
 <xsl:output method="html" /> 
 
 <xsl:template match="/">
  <xsl:call-template name="ADPosition"></xsl:call-template>
 </xsl:template>
 
 <!--广告位-->
 <xsl:template name="ADPosition">
  <xsl:variable name="_adPosition" select="/NewDataSet/Table[iPositionID]" />
  <!--DIV开始-->
  <xsl:element name="div">
   <xsl:attribute name="style">
    <xsl:value-of select="concat('position:relative;overflow:hidden;width:', $_adPosition/iWidthSize, 'px;height:', $_adPosition/iHeightSize, 'px')" />
   </xsl:attribute>
   <OBJECT id="swfAd_{$_adPosition/iPositionID}" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" VIEWASTEXT="">
    <PARAM NAME="Movie" VALUE="" />
    <PARAM NAME="Src" VALUE="" />   
    <PARAM NAME="Quality" VALUE="High" />
   </OBJECT>  
   
   <script language="javascript">
    <xsl:variable name="_ADItems">
     <xsl:call-template name="GetADItems" />
    </xsl:variable>
    
    <xsl:choose>
     <xsl:when test="count(msxsl:node-set($_ADItems)/Item) > 0">
      <xsl:choose>    
       <xsl:when test="$_adPosition/iDisplayType=1">
        <xsl:call-template name="GetRollScript">
         <xsl:with-param name="_iPositionID" select="$_adPosition/iPositionID"></xsl:with-param>
         <xsl:with-param name="_ADItems" select="msxsl:node-set($_ADItems)"></xsl:with-param>
         <xsl:with-param name="_iCycle" select="$_adPosition/iCycle" />
        </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
        <xsl:call-template name="GetRandomScript">
         <xsl:with-param name="_iPositionID" select="$_adPosition/iPositionID"></xsl:with-param>
         <xsl:with-param name="_ADItems" select="msxsl:node-set($_ADItems)"></xsl:with-param>
        </xsl:call-template>
       </xsl:otherwise>
      </xsl:choose>
     </xsl:when>
    </xsl:choose>
   </script>
  </xsl:element>  
 </xsl:template> 
 
 <!--获取指定广告位内广告项-->
 <xsl:template name="GetADItems">
  <xsl:for-each select="/NewDataSet/Table[not(iPositionID) and cFileType='application/x-shockwave-flash']">
   <Item>
    <ADItemID><xsl:value-of select="iADItemID" /></ADItemID>
    <Flash><xsl:choose>
      <xsl:when test="cFileUrl">
       <xsl:value-of select="cFileUrl" />
      </xsl:when>
      <xsl:otherwise>/ADManager/GetFile.aspx?type=3&amp;id=<xsl:value-of select="iADItemID" />
      </xsl:otherwise>
     </xsl:choose>
    </Flash>    
   </Item>
  </xsl:for-each>
 </xsl:template>
 
 <!--获取轮循脚本-->
 <xsl:template name="GetRollScript">
  <xsl:param name="_iPositionID" />
  <xsl:param name="_ADItems" />
  <xsl:param name="_iCycle" />
  <![CDATA[
   function ADFlash(src)
   {
    this.Src = src;
   }
   
   function SimpleFlash(items, oSwf, iCycle)
   {
    var i=0;
    function Roll()
    {  
     if(i >= items.length)
     {
      i=0;
     }
           
     oSwf.Src = items[i].Src;
     oSwf.Movie = oSwf.Src    
     
     i++;
     window.setTimeout(Roll, iCycle*60000);
    }
    this.Roll = Roll;
   }
  ]]>
   var _aditemCollection_<xsl:value-of select="$_iPositionID" /> = new Array();
   var _aditem;
   <xsl:for-each select="$_ADItems/Item">
   _aditem = new ADFlash("<xsl:value-of select="Flash" />");
   _aditemCollection_<xsl:value-of select="$_iPositionID" />.push(_aditem);    
   </xsl:for-each>
   new SimpleFlash(_aditemCollection_<xsl:value-of select="$_iPositionID" />, document.getElementById("swfAd_<xsl:value-of select="$_iPositionID" />"), <xsl:value-of select="$_iCycle" />).Roll();
 </xsl:template>
 
 <!--获取随机脚本-->
 <xsl:template name="GetRandomScript">
 <xsl:param name="_iPositionID" />
  <xsl:param name="_ADItems" />   
   <xsl:variable name="_i" select="dyens:GetRandomInt(count($_ADItems/Item)-1)"></xsl:variable>
   <xsl:variable name="_item" select="$_ADItems/Item[position()=$_i+1]" />    
    var oFlash = document.getElementById("swfAd_<xsl:value-of select="$_iPositionID" />");
    oFlash.Src = "<xsl:value-of select="$_item/Flash" />";
    oFlash.Movie = oFlash.Src;
 </xsl:template>
</xsl:stylesheet> 
--------------------------------------NewWindow.xslt-----------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:dyens="http://localhost/"
 exclude-result-prefixes="dyens msxsl xsl">
 
 <xsl:import href="Comm.xslt"/>
 <xsl:output method="xml" /> 
 
 <xsl:template match="/">
  <xsl:call-template name="ADPosition"></xsl:call-template>
 </xsl:template>
 
 <!--广告位-->
 <xsl:template name="ADPosition">
  <xsl:variable name="_adPosition" select="/NewDataSet/Table[iPositionID]" /> 
   <xsl:variable name="_ADItems">
    <xsl:call-template name="GetADItems" />
   </xsl:variable>
   
   <xsl:if test="count(msxsl:node-set($_ADItems)/Item) > 0">     
     <script language="javascript">      
      <xsl:for-each select="msxsl:node-set($_ADItems)/Item">
       var win = window.open("","_<xsl:value-of select="ADItemID" />","height=<xsl:value-of select="$_adPosition/iHeightSize" />,width=<xsl:value-of select="$_adPosition/iWidthSize" />");
       <xsl:choose>
        <xsl:when test="Flash">
         win.document.write('<xsl:value-of select="'<'" disable-output-escaping="yes"/>OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" VIEWASTEXT<xsl:value-of select="'>'" disable-output-escaping="yes"/><xsl:value-of select="'<'" disable-output-escaping="yes"/>PARAM NAME="Movie" VALUE="<xsl:value-of select="Flash" />"<xsl:value-of select="'>'" disable-output-escaping="yes"/><xsl:value-of select="'<'" disable-output-escaping="yes"/>PARAM NAME="Src" VALUE="<xsl:value-of select="Flash" />"<xsl:value-of select="'>'" disable-output-escaping="yes"/><xsl:value-of select="'<'" disable-output-escaping="yes"/>PARAM NAME="Quality" VALUE="High"<xsl:value-of select="'>'" disable-output-escaping="yes"/><xsl:value-of select="'<'" disable-output-escaping="yes"/>/OBJECT<xsl:value-of select="'>'" disable-output-escaping="yes"/>');
        </xsl:when>
        <xsl:when test="Image">
         <xsl:if test="Href!=''">
         win.document.write("<xsl:value-of select="'<'" disable-output-escaping="yes"/>a href='<xsl:value-of select="Href"/>'<xsl:value-of select="'>'" disable-output-escaping="yes"/>");
         </xsl:if>
         win.document.write("<xsl:value-of select="'<'" disable-output-escaping="yes"/>img border=0 src=<xsl:value-of select="Image" /><xsl:value-of select="'>'" disable-output-escaping="yes"/>");
         <xsl:if test="Href!=''">
         win.document.write("<xsl:value-of select="'<'" disable-output-escaping="yes"/>/a<xsl:value-of select="'>'" disable-output-escaping="yes"/>");
         </xsl:if>
        </xsl:when>
        <xsl:otherwise>
         <xsl:if test="Href!=''">
         win.document.write("<xsl:value-of select="'<'" disable-output-escaping="yes"/>a href='<xsl:value-of select="Href"/>'<xsl:value-of select="'>'" disable-output-escaping="yes"/>");
         </xsl:if>
         win.document.write("<xsl:value-of select="Text" />");
         <xsl:if test="Href!=''">
         win.document.write("<xsl:value-of select="'<'" disable-output-escaping="yes"/>/a<xsl:value-of select="'>'" disable-output-escaping="yes"/>");
         </xsl:if>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:for-each>
     </script> 
   </xsl:if>
 </xsl:template>
 
 <!--获取指定广告位内广告项-->
 <xsl:template name="GetADItems">
  <xsl:for-each select="/NewDataSet/Table[not(iPositionID)]">
   <Item>
    <ADItemID><xsl:value-of select="iADItemID" /></ADItemID>
    <xsl:if test="cFileType='application/x-shockwave-flash'">
     <Flash><xsl:choose>
       <xsl:when test="cFileUrl">
        <xsl:value-of select="cFileUrl" />
       </xsl:when>
       <xsl:otherwise>/ADManager/GetFile.aspx?type=3&amp;id=<xsl:value-of select="iADItemID" />
       </xsl:otherwise>
      </xsl:choose>
     </Flash>
    </xsl:if>
    <xsl:if test="cFileType='image/jpg'">
     <Image><xsl:choose>
       <xsl:when test="cFileUrl">
        <xsl:value-of select="cFileUrl" />
       </xsl:when>
       <xsl:otherwise>/ADManager/GetFile.aspx?type=2&amp;id=<xsl:value-of select="iADItemID" />
       </xsl:otherwise>
      </xsl:choose>
     </Image>
    </xsl:if>
    <xsl:if test="(not(cFileUrl) or cFileUrl='') and not(cFileName)">
     <Text>
      <xsl:value-of select="cTitle" />
     </Text>
    </xsl:if>
    <Href>
     <xsl:if test="cLink and cLink != ''">/ADManager/ADManager.UI/ADControler.aspx?href=<xsl:value-of select="cLink" />&amp;id=<xsl:value-of select="iADItemID" /></xsl:if>
    </Href>
   </Item>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>
  ---------------------------------MarqueeText.xslt------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:dyens="http://localhost/"
 exclude-result-prefixes="dyens msxsl xsl">
 
 <xsl:import href="Comm.xslt"/>
 <xsl:output method="html" />
 
 <xsl:param name="_direction" select="'left'" />
 
 <xsl:template match="/">
  <xsl:call-template name="ADPosition"></xsl:call-template>
 </xsl:template>
 
 <!--广告位-->
 <xsl:template name="ADPosition">
  <xsl:variable name="_adPosition" select="/NewDataSet/Table[iPositionID]" />
  <!--DIV开始-->
  <xsl:element name="div">    
   <xsl:attribute name="style">
    <xsl:value-of select="concat('position:relative;overflow:hidden;width:', $_adPosition/iWidthSize, 'px;height:', $_adPosition/iHeightSize, 'px')" />
   </xsl:attribute>
   
   <xsl:variable name="_ADItems">
    <xsl:call-template name="GetADItems" />
   </xsl:variable>
   
   <xsl:if test="count(msxsl:node-set($_ADItems)/Item) > 0">
    <xsl:element name="MARQUEE">
     <xsl:attribute name="HSPACE">10</xsl:attribute>
     <xsl:attribute name="VSPACE">10</xsl:attribute>
     <xsl:attribute name="BEHAVIOR">SCROLL</xsl:attribute>
     <xsl:attribute name="SCROLLAMOUNT">5</xsl:attribute>
     <xsl:attribute name="SCROLLDELAY">200</xsl:attribute>
     <xsl:attribute name="height">100%</xsl:attribute>
     <xsl:attribute name="DIRECTION"><xsl:value-of select="$_direction" /></xsl:attribute>
     <xsl:for-each select="msxsl:node-set($_ADItems)/Item">
      <xsl:if test="$_direction='left'">
       <xsl:choose>
        <xsl:when test="Href != ''">
         <a href="{Href}"><xsl:value-of select="Text" /></a>
        </xsl:when>
        <xsl:otherwise>
         <xsl:value-of select="Text" />
        </xsl:otherwise>
       </xsl:choose>
               <!--该行为全角空格-->
      </xsl:if>
      <xsl:if test="$_direction='up'">
       <xsl:choose>
        <xsl:when test="Href != ''">
         <a href="{Href}"><xsl:value-of select="Text" /></a>
        </xsl:when>
        <xsl:otherwise>
         <xsl:value-of select="Text" />
        </xsl:otherwise>
       </xsl:choose>  
       <br/>
      </xsl:if>
     </xsl:for-each>
    </xsl:element>
   </xsl:if>
  </xsl:element>
 </xsl:template>
 
 <!--获取指定广告位内广告项-->
 <xsl:template name="GetADItems">
  <xsl:for-each select="/NewDataSet/Table[not(iPositionID)]">
   <Item>
    <ADItemID><xsl:value-of select="iADItemID" /></ADItemID>
    <Text><xsl:value-of select="cTitle" /></Text>
    <Href>
     <xsl:if test="cLink and cLink != ''">/ADManager/ADManager.UI/ADControler.aspx?href=<xsl:value-of select="cLink" />&amp;id=<xsl:value-of select="iADItemID" /></xsl:if>
    </Href>
   </Item>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

------------------------------------FloatAD.XSLT-----------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:dyens="http://localhost/"
 exclude-result-prefixes="dyens msxsl xsl">
 
 <xsl:import href="Comm.xslt"/>
 <xsl:output method="html" /> 
 
 <xsl:template match="/">
  <xsl:call-template name="ADPosition"></xsl:call-template>
 </xsl:template>
 
 <!--广告位-->
 <xsl:template name="ADPosition">
  <xsl:variable name="_adPosition" select="/NewDataSet/Table[iPositionID]" /> 
   <xsl:variable name="_ADItems">
    <xsl:call-template name="GetADItems" />
   </xsl:variable>   
   <xsl:if test="count(msxsl:node-set($_ADItems)/Item) > 0">
     <script language="javascript">
      <xsl:call-template name="GetScriptForFloat" />
      <xsl:for-each select="msxsl:node-set($_ADItems)/Item">
      new randFly("<xsl:value-of select="Image" />", 2, 35 <xsl:if test="Href!=''">,"window.open('<xsl:value-of select="Href"/>')"</xsl:if>);
      </xsl:for-each>
     </script> 
   </xsl:if>
 </xsl:template>
 
 <!--获取指定广告位内广告项-->
 <xsl:template name="GetADItems">
  <xsl:for-each select="/NewDataSet/Table[not(iPositionID) and cFileType='image/jpg']">
   <Item>
    <ADItemID><xsl:value-of select="iADItemID" /></ADItemID>
    <Image><xsl:choose>
      <xsl:when test="cFileUrl">
       <xsl:value-of select="cFileUrl" />
      </xsl:when>
      <xsl:otherwise>/ADManager/GetFile.aspx?type=2&amp;id=<xsl:value-of select="iADItemID" />
      </xsl:otherwise>
     </xsl:choose>
    </Image>
    <Text>
     <xsl:value-of select="cTitle" />
    </Text>
    <Href>
     <xsl:if test="cLink and cLink != ''">/ADManager/ADManager.UI/ADControler.aspx?href=<xsl:value-of select="cLink" />&amp;id=<xsl:value-of select="iADItemID" /></xsl:if>
    </Href>
   </Item>
  </xsl:for-each>
 </xsl:template>
 
 <xsl:template name="GetScriptForFloat">
  <![CDATA[
  var randFlyCount = 0;
  var randFlyCollection = new Array();
  randFly.pause = function(){}
  
  //定义漂浮广告对象;
  function randFly(fileUrl, flyAmount, flyDelay, openUrl)
  {
   this._ID = randFlyCount++;
   this.objPoint = fileUrl;
   this._amount = flyAmount;
   this._delay  = flyDelay;
   this._command   = openUrl;
   this._setTime;
   this._dirX;
   this._dirY;
   this._stepX;
   this._stepY;

   //实例启动函数;
   this.init = function()
   {
    var srcFile = this.objPoint;
    
    this.objPoint = document.createElement("<img src='" + srcFile + "' style='cursor:hand'/>");
    document.body.appendChild(this.objPoint);//生成广告html实体;

    with(this.objPoint)
    {
     style.position = "absolute";
     style.cursor = "hand";
     style.top = (document.body != null)? (document.body.clientHeight - offsetHeight) / 2 : 0;
     style.left = (document.body != null)? (document.body.clientWidth - offsetWidth) / 2 : 0;
     setAttribute("cID",this._ID);//自定义属性;
     setAttribute("reflectClass",this);//自定义属性;
     attachEvent("onclick",new Function(this._command));
     attachEvent("onmouseover",this.pause);//设置鼠标停留事件;
     attachEvent("onmouseout",this.restart);//设置鼠标移出事件;
    }
    this._stepX = this._amount;
    this._stepY = this._amount;

    this._dirX  = rBool();
    this._dirY  = rBool();
    randFlyCollection.push(this);
    this.start();
   }
   
   //方向调整函数;
   this.start = function()
   {
    if(this._dirX == true)
    {
     if(this.objPoint.offsetLeft + this._stepX + this.objPoint.offsetWidth < document.body.scrollLeft+document.body.clientWidth)
     {      
      this.objPoint.style.left = this.objPoint.offsetLeft + this._stepX;
     }
     else
     {
      this.objPoint.style.left = this.objPoint.offsetLeft - this._stepX
      this._dirX = false;
     }
    }
    else
    {
     if(this.objPoint.offsetLeft - this._stepX > 0)
     {
      this.objPoint.style.left = this.objPoint.offsetLeft - this._stepX;
     }
     else
     {
      this.objPoint.style.left = this.objPoint.offsetLeft + this._stepX;
      this._dirX = true;
     }
    }

    if(this._dirY == true)
    {    
     if(this.objPoint.offsetTop + this._stepY + this.objPoint.offsetHeight < document.body.scrollTop+document.body.clientHeight)
     {      
      this.objPoint.style.top = this.objPoint.offsetTop + this._stepY;
     }
     else
     {
      this.objPoint.style.top = this.objPoint.offsetTop - this._stepX
      this._dirY = false;
     }
    }
    else
    {
     if(this.objPoint.offsetTop - this._stepY > 0)
     {
      this.objPoint.style.top = this.objPoint.offsetTop - this._stepY;
     }
     else
     {
      this.objPoint.style.top = this.objPoint.offsetTop + this._stepY;
      this._dirY = true;
     }
    } 
    this._setTime = setTimeout("randFlyCollection["+this.objPoint.cID+"].start()",this._delay);
   }
   this.pause = function()
   {
    clearTimeout(event.srcElement.reflectClass._setTime);
   }
   this.restart = function()
   {
    event.srcElement.reflectClass.start();
   }
   this.init();
  }

  function rBool()
  {
   return (Math.random() > 0.5)? true : false;
  } 
  ]]>
 </xsl:template>
</xsl:stylesheet>

 

Advertisements
此条目发表在Xml/Xslt分类目录。将固定链接加入收藏夹。

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s