通过xslt添加超链接到Excel单元格

我有一个xml文件和一个xslt样式表文件。

我怎样才能通过特定的XML字段添加超链接到xslt文件中特定的Excel单元格。

我有以下伪代码,但不知道如何在xslt文件中设置此。

if (xmlAttribute =="Beleg") { href = "http://www.xyz.de/beleg.php?beleg=$fieldvalue } else if (xmlAttribute == "Lieferant") { href = "http://www.xyz.de/lieferant.php?lieferant=$fieldvalue } else { // no link } 

有人能帮帮我吗。

在这里我的xml和xslt

XML:

 <xml> <s:Schema id="RowsetSchema" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> <s:ElementType name="row" content="eltOnly"> <s:AttributeType name="ART"> <s:datatype dt:type="string" dt:maxLength="3" rs:maybenull="false" /> </s:AttributeType> <s:AttributeType name="BELEG"> <s:datatype dt:type="string" dt:maxLength="63" rs:maybenull="false" /> </s:AttributeType> <s:AttributeType name="BELEGPOSITION"> <s:datatype dt:type="i2" /> </s:AttributeType> <s:AttributeType name="BESTELLUNGSDATUM"> <s:datatype dt:type="dateTime" /> </s:AttributeType> <s:AttributeType name="VERURSACHERARTIKEL"> <s:datatype dt:type="string" dt:maxLength="22" rs:maybenull="false" /> </s:AttributeType> <s:AttributeType name="WIEDERBESCHAFFUNGSZEIT"> <s:datatype dt:type="i2" /> </s:AttributeType> <s:AttributeType name="LIEFERANT"> <s:datatype dt:type="string" dt:maxLength="15" /> </s:AttributeType> <s:AttributeType name="LIEFERANTENNAME"> <s:datatype dt:type="string" dt:maxLength="63" /> </s:AttributeType> <s:AttributeType name="BEARBEITER"> <s:datatype dt:type="string" dt:maxLength="50" /> </s:AttributeType> <s:AttributeType name="VERURSACHER"> <s:datatype dt:type="string" dt:maxLength="19" /> </s:AttributeType> <s:AttributeType name="VERURSACHERPOSITION"> <s:datatype dt:type="string" dt:maxLength="31" /> </s:AttributeType> <s:AttributeType name="ERSTELLER"> <s:datatype dt:type="string" dt:maxLength="31" /> </s:AttributeType> <s:AttributeType name="ENDE"> <s:datatype dt:type="dateTime" /> </s:AttributeType> <s:AttributeType name="BEDARFSTERMIN"> <s:datatype dt:type="dateTime" /> </s:AttributeType> <s:AttributeType name="LIEFERTERMIN"> <s:datatype dt:type="dateTime" /> </s:AttributeType> <s:AttributeType name="VERSPAETUNG"> <s:datatype dt:type="int" /> </s:AttributeType> <s:AttributeType name="UNTERSCHREITUNG"> <s:datatype dt:type="int" /> </s:AttributeType> <s:extends type="rs:rowbase" /> </s:ElementType> </s:Schema> <rs:data xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> <z:row ART="ZB" BELEG="982831" BELEGPOSITION="4" BESTELLUNGSDATUM="2012-08-27T00:00:00" VERURSACHERARTIKEL="A16" WIEDERBESCHAFFUNGSZEIT="28" LIEFERANT="123" LIEFERANTENNAME="XXXcOMPANY" BEARBEITER="HarryPotter" VERURSACHER="0.123" VERURSACHERPOSITION="470" ERSTELLER="Max Mustermann" ENDE="2012-12-20T10:10:00" BEDARFSTERMIN="2011-12-19T00:00:00" LIEFERTERMIN="2011-12-31T00:00:00" VERSPAETUNG="-36" UNTERSCHREITUNG="46" /> <z:row ART="ZB" BELEG="982838" BELEGPOSITION="4" BESTELLUNGSDATUM="2012-08-27T00:00:00" VERURSACHERARTIKEL="B16" WIEDERBESCHAFFUNGSZEIT="28" LIEFERANT="134" LIEFERANTENNAME="XXXcOMPANY" BEARBEITER="HarryPotter" VERURSACHER="0.234" VERURSACHERPOSITION="472" ERSTELLER="Max Mustermann" ENDE="2012-12-20T10:10:00" BEDARFSTERMIN="2012-12-19T00:00:00" LIEFERTERMIN="2013-12-31T00:00:00" VERSPAETUNG="-376" UNTERSCHREITUNG="86" /> </rs:data> </xml> 

XSLT特定部分:

 <Row> <xsl:for-each select="../../s:Schema/s:ElementType/s:AttributeType"> <Cell> <xsl:variable name="v" select="$x/@*[name()=current()/@name]" /> <xsl:choose> <xsl:when test="string-length($v)=0"> </xsl:when> <xsl:when test="s:datatype[@dt:type='dateTime']"> <Data ss:Type="DateTime"> <xsl:value-of select="$v" /> </Data> </xsl:when> <xsl:otherwise> <Data ss:Type="String"> <xsl:value-of select="$v" /> </Data> </xsl:otherwise> </xsl:choose> </Cell> </xsl:for-each> </Row> 

如果您想了解如何在Excel Spreadsheet XML中做些什么,那么最好的办法就是问问Excel本身! 进入Excel,在单元格中input一个URL并将其保存为XML Spreadsheet格式。 然后在记事本(或您select的文本编辑器)中打开保存的文件。 希望你能看到像这样的东西

 <Cell ss:StyleID="s62" ss:HRef="http://stackoverflow.com/"> <Data ss:Type="String">http://stackoverflow.com/</Data> </Cell> 

因此,您需要在XSLT中执行的操作是确保将ss:HRef属性添加到Cell元素(在创buildData元素之前)。 像这样的东西

 <xsl:otherwise> <xsl:choose> <xsl:when test="$attribute = 'Beleg'"> <xsl:attribute name="HRef"> <xsl:text>http://www.xyz.de/beleg.php?beleg=<xsl:text> <xsl:value-of select="$fieldvalue" /> </xsl:attribute> </xsl:when> </xsl:choose> <Data ss:Type="String"> <xsl:value-of select="$v" /> </Data> </xsl:otherwise> 

显然你必须确保$属性被设置为你想要检查的属性的值,但它应该给你的一般想法。

编辑:您可能需要确保您设置的URL是绝对地址(以“http://”开头)而不是相对的(以“../”开头)