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

Discussion in 'XML' started by mark4asp, Dec 21, 2007.

  1. mark4asp

    mark4asp Guest

    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.
     
    mark4asp, Dec 21, 2007
    #1
    1. Advertising

  2. mark4asp

    TOUDIdel Guest

    Uzytkownik "mark4asp" <> napisal w wiadomosci
    news:01dc935f$0$21091$...
    >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
     
    TOUDIdel, Dec 21, 2007
    #2
    1. Advertising

  3. mark4asp

    mark4asp Guest

    TOUDIdel wrote:

    >
    > Uzytkownik "mark4asp" <> napisal w wiadomosci
    > news:01dc935f$0$21091$...
    > > 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?
     
    mark4asp, Dec 21, 2007
    #3
  4. Re: XSLT problem. Can I please have a little help here to createa hyperlink.


    >
    > 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
     
    David Carlisle, Dec 21, 2007
    #4
  5. mark4asp

    TOUDIdel Guest

    U¿ytkownik "mark4asp" <> napisa³ w wiadomo¶ci
    news:00c319cc$0$25824$...
    > 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
     
    TOUDIdel, Dec 23, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page