469,283 Members | 2,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

copying all but one type of Nodes in XSLT

Hello,

I'm unsing well-formed XML HTML tags as my formatted "Description"
content in a XML Database, so I have stuff of the sort:

<Description lang='en'><b>This is bold Text</band this is not<i>and
this is italic text</i></Description>

So far, nothing too dramatic, when I want to reproduce this as an HTML
output, I used the <xsl:copy-ofcommand to copy the whole node over
to my HTML output.

Now here comes where I have an issue:

I want to use a specific tag <spec name='specname'/to insert
"Specifications" related to the product WITHIN the formatted text...
so it could be anywhere under <Descriptionor a <btag, or a <i>
tag ...

The idea is that products are built out of other products, and I want
to be able to have the specification propagate through to the higher
level products, so I only want to "reference" the spec name in the
Description, and pull it out from the lower level product at the time
of output.

So, my problem is to "fill in" my <spec name='specname'/tag with its
content coming from somewhere else.
The <xsl:copy-ofcan no longer be used here, and it doesn't do the
job, but then is there an easy way to "transfer" all of the XML/HTML
and just replace the tag i want to replace?

I obviously need to parse the whole thing, but tags can be anything,
anywhere, (from the selection of formatting tags <b>, <i>, <u>, <br/>,
<p>, <sub>, <supetc...)

I'm not so proficient in XPath to figure out what would be the path I
want to select to transfer all tags but my <spectag, and when
bumping into one, replacing it with my data.

any insight?

Suggestion appreciated!

Thanks

Jul 14 '07 #1
3 2063
I tried this:

<xsl:template match="@* | node()">
<xsl:choose>
<xsl:when test="@name">
print Spec here
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

and it works fine, but I am not sure why the following doesn't:

<xsl:template match="@* | node()">
<xsl:choose>
<xsl:when test="spec">
print Spec here
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

ideally I need to process more than 1 attribute from the <spectag,
so i'd like to trigger it on that node name, not on the attribute

any idea?

Jul 14 '07 #2
Wizfrog wrote:
I tried this, but it always seem to use the @* | node() by default,
and never gets to the match='spec[...]' template even when getting to
a <spectag...
In that case, the spec element isn't matching. Either the predicate is
wrong or you've got namespaces involved. Think about why, or give us
enough information to diagnose.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 14 '07 #3
Wizfrog wrote:
<xsl:when test="@name">
True when the current node has a name attribute, ie the <spec>.
<xsl:when test="spec">
True when the current node has a spec element child, ie the <spec>'s
parent.

xsl:when is not the best way to do this -- use templates -- but if you
must, you could try
<xsl:when test="self::spec">
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Johannes Lebek | last post: by
9 posts views Thread by Rolf Kemper | last post: by
2 posts views Thread by Claudio Jolowicz | last post: by
2 posts views Thread by JJ | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.