Re: using css in html embedded in xml rendered using xsl with javascript (phew)

Discussion in 'XML' started by confused, May 27, 2007.

  1. confused

    confused Guest

    On 26 May, 00:06, David Carlisle <>
    wrote:
    > confused wrote:
    > > Oh and this works but only in mozilla not IE6

    >
    > > <product>
    > > <name><specialOffer class="specialOfferStyle">a great product</
    > > specialOffer></name>
    > > </product>

    >
    > since you are using xsl anyway why not just generate the standard html
    > +css that you said worked earlier rather than a mixture if html and
    > your own xml markup?
    >
    > adding a template like
    >
    > <xsl:template match="specialOffer">
    > <div class="specialOffer">
    > <xsl:apply-templates/>
    > </div>
    > </xsl:template>
    >
    > should be all you need, together with the css that styles div.specialOffer
    >
    > --
    > <a href="http://dpcarlisle.blogspot.com">David</a>


    Thankyou for the response

    I wanted to just be able to change the style of some things from the
    XML as a last minute thing rather than have to delve into the XSL
    every time. I haven't actually used the template match paste the "/"
    stage so i'll have to see how this works. Currently my XSL searches
    for each product entry and then extracts the name. are you saying
    that by using the template match thingy I could effectively pre-
    processes the name entry so that those with special offer around them
    would display differently.

    Or would I have to have a separate tage for each product to say if
    special offer formatting should apply

    Or when dealing with the name tag would I see if it contained a
    specialOffer tag or not.

    P.
    confused, May 27, 2007
    #1
    1. Advertising

  2. Re: using css in html embedded in xml rendered using xsl with javascript(phew)

    > confused wrote:

    > are you saying
    > that by using the template match thingy I could effectively pre-
    > processes the name entry so that those with special offer around them
    > would display differently.


    unlike CSS which annotates an existing document tree with style
    information, XSLT is a transformation language. It's not a case of
    _altering_ the display of individual nodes. If you specify an xsl
    transformation, your original XML document is not displayed at all: it
    is just used as input to the xsl stylesheet. It is then totally the
    responsiblity of that stylesheet to generate a document that is
    displayed by the browser. By default an XSLT stylesheet doesn't generate
    any elements in the result tree at all, so any elements that are to be
    displayed have to be generated by the stylesheet (perhaps by explictly
    copying them from the original document). Since you are targetting an
    HTML browser, it often makes sense to generate html for it to dsplay
    natively rather than generate custom elements that you then further
    style with css, but it all depends on the application.

    David
    --
    http://dpcarlisle.blogspot.com
    David Carlisle, May 27, 2007
    #2
    1. Advertising

  3. confused

    [Jongware] Guest

    "confused" <> wrote in message
    news:...
    > On 26 May, 00:06, David Carlisle <>
    > wrote:
    > > confused wrote:
    > > > Oh and this works but only in mozilla not IE6

    > >
    > > > <product>
    > > > <name><specialOffer class="specialOfferStyle">a great product</
    > > > specialOffer></name>
    > > > </product>

    > >
    > > since you are using xsl anyway why not just generate the standard html
    > > +css that you said worked earlier rather than a mixture if html and
    > > your own xml markup?
    > >
    > > adding a template like
    > >
    > > <xsl:template match="specialOffer">
    > > <div class="specialOffer">
    > > <xsl:apply-templates/>
    > > </div>
    > > </xsl:template>

    [etc.]
    > Or would I have to have a separate tage for each product to say if
    > special offer formatting should apply
    >
    > Or when dealing with the name tag would I see if it contained a
    > specialOffer tag or not.


    <xsl:template match="@specialOffer">
    <span class="specialOffer">
    <xsl:apply-templates/>
    </span>
    </xsl:template>

    will <span> everything you specify with a 'specialOffer' attribute, e.g.,
    <product specialOffer="y">
    where the "y" is just an obligatory placeholder -- "n" would also work. (Parsing
    for either "y" or "n" is, of course, also possible, but just that bit more
    work.)
    Depending on your desired output, you could replace the <span> with a <div>, or
    even switch between these with appropriate templates.

    [Jongware]
    [Jongware], May 28, 2007
    #3
  4. confused

    Pavel Lepin Guest

    [Jongware] <> wrote in
    <3f972$465ac0f9$3ec3d632$>:
    > "confused" <> wrote
    >> On 26 May, 00:06, David Carlisle
    >> <> wrote:
    >> > confused wrote:
    >> > > <product>
    >> > > <name><specialOffer class="specialOfferStyle">a
    >> > > great product</
    >> > > specialOffer></name>
    >> > > </product>
    >> >
    >> > <xsl:template match="specialOffer">
    >> > <div class="specialOffer">
    >> > <xsl:apply-templates/>
    >> > </div>
    >> > </xsl:template>

    >> Or when dealing with the name tag would I see if it
    >> contained a specialOffer tag or not.

    >
    > <xsl:template match="@specialOffer">
    > <span class="specialOffer">
    > <xsl:apply-templates/>
    > </span>
    > </xsl:template>


    You probably mean:

    <xsl:template match="*[@specialOffer]">

    > will <span> everything you specify with a 'specialOffer'
    > attribute, e.g., <product specialOffer="y">
    > where the "y" is just an obligatory placeholder -- "n"
    > would also work. (Parsing for either "y" or "n" is, of
    > course, also possible, but just that bit more work.)


    <xsl:template match="*[@specialOffer='y']">

    --
    Pavel Lepin
    Pavel Lepin, May 28, 2007
    #4
    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