This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: testing element's contents


Joerg,

Thanks. Very close now...

The only thing causing a problem now is that a Media
element can contain two child elements, Link and/or
Caption. I actually had a Link element outside of a
Media element before, but that *SHOULD* not happen.
Both the Link and Caption elements contain text nodes.
So, something like this:

<p>
   <Media type="image" id="1"
file="http://www.mylocal.gov/images/aero.gif";
width="54" height="54" border="" alt="Picture of the
shuttle parachute.">
      <Link url="mytestfile.htm" type="external"/>
      <Caption align="bottom">Picture of the shuttle
parachute.</Caption>
   </Media>
</p>

will pass the test even though it is only an image.

Sorry I left that out. That is the only snag left
preventing your solution from working.

I tried adding to it myself, but I just do not
understand axis conditionals well enough.

<xsl:when
test="descendant::node()[normalize-space()][not(self::Media
or descendant::Link or descendant::Caption)]">
   <p><xsl:apply-templates/></p>
</xsl:when>

--nate


--- Joerg Heinicke <joerg.heinicke@gmx.de> wrote:
> Hi Nathan,
> 
> it should work in your example too, because there is
> a text node as 
> child of the <Link>, so the test is passed.
> 
> Only one comment:
> 
> <p>
>      <Link>
> 
>      </Link>
> </p>
> 
> The above passes the test because of spaces and line
> breaks between <p> 
> and <Link> or between <Link> and </Link>. To avoid
> this you can test on 
> nodes, which don't consist of only whitespaces
> characters. Use 
> normalize-space() for this 
>
(http://www.w3.org/TR/xpath#function-normalize-space):
> 
> <xsl:when
>
test="descendant::node()[normalize-space()][not(self::Link
> or 
> self::Media)]">
>      <p><xsl:apply-templates/></p>
> </xsl:when>
> 
> => If a descendant node exists, that consists not
> only of whitespace 
> characters, that is not <Link> or <Media>, wrap it
> in <p>.
> 
> Regards,
> 
> Joerg
> 
> Nathan Shaw wrote:
> > Excellent Joerg! The only place this would not
> work is
> > if I have a paragraph element with only a Link
> element
> > in it, such as:
> > 
> > <p><Link href="blah.html">This is a
> link</Link></p>
> > 
> > I need those to pass through the test and be
> wrapped
> > in a p tag. Otherwise, it catches everything else
> I
> > need!
> > 
> > Thank you! That gives me great direction...
> > 
> > --nate
> > 
> > 
> > --- Joerg Heinicke <joerg.heinicke@gmx.de> wrote:
> > 
> >><xsl:when test="descendant::node()[not(self::Link
> or
> >>self::Media)]">
> >>   <p><xsl:apply-templates/></p>
> >></xsl:when>
> >>
> >>If there is any descendant node (including
> elements,
> >>comments, PIs, 
> >>text), which is not element Link or element Media,
> >>create <p> in output 
> >>tree.
> >>
> >>Regards,
> >>
> >>Joerg
> >>
> >>Nathan Shaw wrote:
> >>
> >>>hi all,
> >>>
> >>>Thanks to everyone who gave me advice on my
> >>
> >>previous
> >>
> >>>post about images and captions. Now, I have
> >>
> >>another
> >>
> >>>tricky lil' xslt problem. If a paragraph element
> >>>contains ONLY a media element OR a media element
> >>>surrounded by a link element and nothing more
> >>
> >>(read,
> >>
> >>>no other nodes, be they text or not), such as:
> >>>
> >>><p><img
> >>>src="http://www.mylocal.gov/images/nasausa.gif";
> >>>height="255" width="432"/></p>
> >>>
> >>>I need to strip the p tags out of resulting
> >>
> >>output.
> >>
> >>>However, if it does contain other nodes, such as:
> >>>
> >>><p><img
> >>>src="http://www.mylocal.gov/images/nasausa.gif";
> >>>height="255" width="432"/>This is my news
> release.
> >>
> >>The
> >>
> >>>authors will be typing the news release content
> in
> >>>here! I am not sure what this news release is
> even
> >>>about, but lets see how it comes out in XML,
> shall
> >>
> >>we?
> >>
> >>>As I see it coming out as:</p>
> >>>
> >>>I need to leave it alone.
> >>>
> >>>Here is what I have so far. It only looks to see
> >>
> >>if a
> >>
> >>>media element or a media element wrapped by a
> link
> >>>element exists, but does not consider if there is
> >>
> >>a
> >>
> >>>text node after a media or link element.
> >>>
> >>><xsl:template match="p">
> >>><xsl:choose>
> >>>	<xsl:when test="((descendant::*[1])[self::Link]
> >>
> >>and
> >>
> >>>(descendant::*[2])[self::Media]) or
> >>>
> >>
> >
>
(descendant::*[1])[self::Media]"><xsl:apply-templates
> > 
> >>>/></xsl:when>
> >>>	<xsl:otherwise><p><xsl:apply-templates
> >>>/></p></xsl:otherwise>
> >>></xsl:choose>
> >>></xsl:template>
> >>>
> >>>Thoughts? Ideas? Criticisms?
> >>>
> >>>--nate
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]