|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Html -> Xml -> Xslt -> Html
Hi, need major help. I got some XML which is basicly html, sample here:
<img src="/images/msword.gif"/> <a href="ltsfinaljuly02.doc">Word</a> <img src="/images/pdf.gif"/> <a href="ltsfinaljuly02">PDF</a> All i wanna do is in XSLT is check if the "href" link is to a .doc file. if so, add some attributes like target="_blank" and title="This will open in a new page" then output it. |
|
#2
|
||||
|
||||
|
Try this:
Code:
<xsl:if test"substring(@href, string-length(@href)-3, string-length(@href))='.doc'"> target="_blank" </xsl:if> |
|
#3
|
|||
|
|||
|
xsl so far
This is the xsl i have so far but it does'nt add the attributes.
<xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="title"> <h3><xsl:apply-templates/></h3> </xsl:template> <xsl:template match="a|area"> <xsl: param name="href-uri"> <!-- pdf, doc, ppt, xls target="_blank"--> <!-- links that start http(s) or got a : do the same --> <!-- for both above add title attribute "This link will open in a new window"--> <xsl:choose> <!-- handles relative URIs for href attributes --> <xsl:when test="contains(@href, '.pdf') or contains(@href, '.doc') or contains(@href, '.ppt') or contains(@href, '.xls') or contains(@href, ':')"> <xsl:element name = "{//a}" > <xsl:attribute name = "target" >_blank</xsl:attribute> <xsl:attribute name = "title" >This link will open in a new window</xsl:attribute> <xsl:apply-templates /> </xsl:element> </xsl:when> <xsl: otherwise> <xsl:value-of select="@href"/> </xsl: otherwise> </xsl:choose> </xsl: param> <xsl:copy> <xsl:attribute name="href"> <xsl:value-of select="$href-uri" /> </xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> |
|
#4
|
||||
|
||||
|
Why do want to write a struture like:
Code:
<xsl:element name="{//a}" >
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:attribute name="title">This link will open in a new window</xsl:attribute>
<xsl:apply-templates />
</xsl:element>
in an attribute? Code:
<xsl:attribute name="href">
<xsl:value-of select="$href-uri" />
</xsl:attribute>
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Html -> Xml -> Xslt -> Html |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|