xml - XSLT copy-of but change values -
i have xml file has non standard html elements so: note: paragraphs have been shortend.
<content> sacrifice. it's mass effect 3's major theme... <p /> mass effect time , place; d... <p /> mass effect 3 focused more on plot th... <p /> <img url="me3_img1.jpg">plenty of games feat...</img> star wars, mass effect 3 inc... <p /> reapers aren't adver... <p /> <img url="me3_img2.jpg">if looks kill..</img> series' focus on player choice vi... <p /> intense narrative met wi... <p /> <img url="me3_img3.jpg">the sun sett...</img> these exquis... </content>
each gap between paragraphs. each image must appear in-between paragraphs apear in content, must have caption, content being between , note has url , not src, must change.
my current xslt copy-of, , css fixes layout, img not displaying because can't change url src, aswell set caption.
please help.
update:
<xsl:for-each select='./review/content/child::*'> <xsl:value-of select="name()"/> <xsl:choose> <xsl:when test="name()='p'"> <p /> </xsl:when> <xsl:when test="name()='img'"> <div class="reviewimage"> <img> <xsl:attribute name="src"> <xsl:value-of select="./@url"/> </xsl:attribute> </img> <xsl:value-of select="."/> </div> </xsl:when> <xsl:otherwise> <xsl:value-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:for-each>
it not outputing of text(). images , captions sorted though.
solution found:
<xsl:for-each select='./review/content/node()'> <xsl:choose> <xsl:when test="name()='p'"> <p /> </xsl:when> <xsl:when test="name()='img'"> <div class="reviewimage"> <img> <xsl:attribute name="src"> <xsl:value-of select="./@url"/> </xsl:attribute> </img> <xsl:value-of select="."/> </div> </xsl:when> <xsl:otherwise> <xsl:value-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:for-each>
the point of copy-of
copy content unchanged input tree output tree.
in order change between input , output trees, want use apply-templates
, template
.
if wish output element on output tree same name on input tree, different content, can use copy
in template, , fill "copy" appropriate content.
Comments
Post a Comment