469,601 Members | 2,172 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,601 developers. It's quick & easy.

XSLT problem. Can I please have a little help here to create a hyperlink.

I want to write a xslt template to create a xhtml 1.0 (transitional)
file which will be sent in as email.

Here is a typical xml data file:

<BatchEmail>
<Domain>www.myDomain.com</Domain>
<Destination>
<Salutation>Hi Mark</Salutation>
<UniqueID>4120</UniqueID>
<Folder>Lite</Folder>
</Destination>
<Reports>
<Report ID="3434">
<Headline>'Triffids' Are Invading!</Headline>
<Preface>Giant mobile plant-like creatures have descending on
Cheltenham and are attacking all animals in sight. Scientists have
named these mysterious creatures 'Triffids'.</Preface>
</Report>
<Report ID="3435">
<Headline>Martian Ambassador Causes Diplomatic Incident</Headline>
<Preface>The Martian ambassador has caused a diplomatic incident
after it accidently eat the Big Apple. On immediately regurgitating New
York City the Ambassador was heard to mutter 'didn't taste anything
like an apple'</Preface>
</Report>
</Reports>
</BatchEmail>
This is what I need the xlst to create from that:

<p>Hi Mark,</p>
<h4>'Triffids' Are Invading!</h4>
<p>Giant mobile plant-like creatures have descending on Cheltenham and
are attacking all animals in sight. Scientists have named these
mysterious creatures 'Triffids'.</p>
<p>Read the full report here:<br /><a target="_blank"
href="http://www.myDomain.com/Lite/ViewReport.aspx?ReportID=3434">http:/
/www.myDomain.com/Lite/ViewReport.aspx?ReportID=3434</a></p>
<h4>Martian Ambassador Causes Diplomatic Incident</h4>
<p>The Martian ambassador has caused a diplomatic incident after it
accidently eat the Big Apple. On immediately regurgitating New York
City the Ambassador was heard to mutter 'didn't taste anything like an
apple'</p>
<p>Read the full report here:<br /><a target="_blank"
href="http://www.myDomain.com/Lite/ViewReport.aspx?ReportID=3435">http:/
/www.myDomain.com/Lite/ViewReport.aspx?ReportID=3435</a></p>
When the xml file has a Folder value of Full (in place of Lite). I'd
like a slightly different xhtml (i.e. with an extra line):

<p>Hi Mark,</p>
<h4>'Triffids' Are Invading!</h4>
<p>Giant mobile plant-like creatures have descending on Cheltenham and
are attacking all animals in sight. Scientists have named these
mysterious creatures 'Triffids'.</p>
<p>Read the full report here:<br /><a target="_blank"
href="http://www.myDomain.com/Full/ViewReport.aspx?ReportID=3434">http:/
/www.myDomain.com/Full/ViewReport.aspx?ReportID=3434</a></p>
<h4>Martian Ambassador Causes Diplomatic Incident</h4>
<p>The Martian ambassador has caused a diplomatic incident after it
accidently eat the Big Apple. On immediately regurgitating New York
City the Ambassador was heard to mutter 'didn't taste anything like an
apple'</p>
<p>Read the full report here:<br /><a target="_blank"
href="http://www.myDomain.com/Full/ViewReport.aspx?ReportID=3435">http:/
/www.myDomain.com/Full/ViewReport.aspx?ReportID=3435</a></p>
<p>You can do a full search of our database at the search page: <a
target="_blank"
href="http://www.myDomain.com/Search/Search.aspx">http://www.myDomain.co
m/Search/Search.aspx</a></p>
I'm having some trouble creating the the url in the hyperlink. For
instance my editor shows it as so (in the .net 2.0 framework, Browser
object windown):

http://{$domain}/{$folder}/ViewReport.aspx?ReportID=1001

Navigating from there takes me to this page:

http://%7B$domain%7D/{$folder}/ViewReport.aspx?ReportID=1001

That comes from the following xslt:

<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:v
alue-of select="@ID"/></span>

That xslt snippet above is itself inside a loop. So the relevant part
is:

<xsl:variable name="domain" select="BatchEmail/Domain"/>
<xsl:variable name="folder" select="BatchEmail/Destination/Folder"/>
<xsl:for-each select="BatchEmail/Reports/Report">

blah blah ...

<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:v
alue-of select="@ID"/></span>

blah blah blah ...
<xsl:if test="$folder = 'Full'">
blah blah blah blah ...
</xsl:if>

blah blah blah blah blah ...

</xsl:for-each>
[the 1001 there is OK, it's just a place holder for the actual value
from the xml. The editor doesn't know anthing about an actual data file
at this stage as email posting is not yet running (as I haven't even
saved my xslt template yet.)

I having tested this program yet as I need to enter the relevant 'Lite'
users in the database, make sure the web service is propertly running
etc. and I'm not confident with that url above.
Dec 21 '07 #1
4 2573

Uzytkownik "mark4asp" <ma******@gmail.comnapisal w wiadomosci
news:01**********************@news.astraweb.com...
>I want to write a xslt template to create a xhtml 1.0 (transitional) file
which will be sent in as email.

<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:v
alue-of select="@ID"/></span>
should be like that:
<a target="_blank"><xsl:attribute
name="href">http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://<xsl:value-of select="$domain"/>//<xsl:value-of
select="$folder"/>//ViewReport.aspx?ReportID=<xsl:v
alue-of select="@ID"/></span>

--
td
XMLguru.net
Dec 21 '07 #2
TOUDIdel wrote:
>
Uzytkownik "mark4asp" <ma******@gmail.comnapisal w wiadomosci
news:01**********************@news.astraweb.com...
I want to write a xslt template to create a xhtml 1.0
(transitional) file which will be sent in as email.


<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:v
al ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl
:v alue-of select="@ID"/></span>
should be like that:
<a target="_blank"><xsl:attribute
name="href">http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:val ue-of
select="@ID"/></xsl:attribute<span
class="link2">http://<xsl:value-of select="$domain"/>//<xsl:value-of
select="$folder"/>//ViewReport.aspx?ReportID=<xsl:v alue-of
select="@ID"/></span>
So if I reduce it to the simplest form, is this it:

<a target="_blank" class="link2"><xsl:attribute
name="href">http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:value-of
select="@ID"/></xsl:attribute>
http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:value-of select="@ID"/>
</a>

I notice you have two / where I only have one (in the display part of
the hyperlink). Is your's a typo or is my hyperlink above wrong?
Dec 21 '07 #3
>
I'm having some trouble creating the the url in the hyperlink. For
instance my editor shows it as so (in the .net 2.0 framework, Browser
object windown):
<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>

{} braces are just character data when used in element content. You have
to use xsl:value-of in that context (as you did for @ID)
so
<a target="_blank"><xsl:attribute
name="href">http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:value-of
select="@ID"/></xsl:attribute>

or more simply use attribute value templates:

<t target="_blank"
href="http://{$domain}/{$folder}/ViewReport.aspx?ReportID={@ID}">

David

--
http://dpcarlisle.blogspot.com
Dec 21 '07 #4

Użytkownik "mark4asp" <ma******@gmail.comnapisał w wiadomo¶ci
news:00**********************@news.astraweb.com...
I notice you have two / where I only have one (in the display part of
the hyperlink). Is your's a typo or is my hyperlink above wrong?
what's the problem? there are many equivalent solutions
--
td
Dec 23 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Victor | last post: by
2 posts views Thread by Flyzone | last post: by
2 posts views Thread by chris | last post: by
7 posts views Thread by Harolds | last post: by
2 posts views Thread by Stephen | last post: by
2 posts views Thread by Craig | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.