简体   繁体   中英

how to pass a link from xml file to xslt

I have a short question. I have a link.xml file which contains a link location like:

<xml>
<property name="link" value="www.something.com/somethinggood">
</xml>

or it could be like:

<xml>
<link>www.something.com/somethinggood</link>
</xml>

and i need to pass it to xslt whick contains a href tag:

    <td>
    <a href=" link " target="_blank"> somethinggood </a>
    </td>

How can i pass that link from my xml file to xsl file?

Thank you for Your answers

You will need two XSLT rules for this:

<xsl:template match="property[@name='link']">
  <a href="{@value}"><xsl:value-of select="substring-after(@value, '/')"/></a>
</xsl:template>

<xsl:template match="link>
  <a href="{text()}"><xsl:value-of select="substring-after(text(), '/')"/></a>
</xsl:template>

In the more general case in which the URL contains slashes before the site address we will still have to tune this a little bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM