xml - XSLT selecting text that contains strong tags -
i'm trying transformation on xml using xslt.
my xml is;
<body> <p> <a href="http://www.zz.com/abc/z/0/z3970z88-0475-11dz-8603-00144zeabdc1.html#slide0"></a> <strong>strong</strong> text </p> </body> and want transform into;
<body> <slideshow data-uuid="z3970z88-0475-11dz-8603-00144zeabdc1/> <p>some <strong>strong</strong> text</p> </body> what have far is;
<xsl:template match="/body/p[a[substring(@href, string-length(@href) - 6) = '#slide0' , string-length(text()) = 0] , count(*) = 1]"> <xsl:apply-templates select="a" /> <xsl:if test="string-length(text()) > 0"> <p> <xsl:value-of select="text()"/> </p> </xsl:if> </xsl:template> <xsl:template match="a[substring(@href, string-length(@href) - 6) = '#slide0' , string-length(text()) = 0]"> <slideshow> <xsl:attribute name="data-uuid"> <xsl:value-of select="substring-before(substring(@href, string-length(@href) - 47), '.html#slide0')" /> </xsl:attribute> </xsl:template> but works if text doesn't have children, such <strong> tag or <a> tag.
does have solution pick up.
i have come xslt. i'm not sure if if fit every purpose can come with, solve example gave here:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/body/p[a]"> <xsl:apply-templates select="a" /> <p> <xsl:copy-of select="./node()[not(self::a)]" /> </p> </xsl:template> <xsl:template match="a[substring(@href, string-length(@href) - 6) = '#slide0' , string-length(text()) = 0]"> <slideshow> <xsl:attribute name="data-uuid"> <xsl:value-of select="substring-before(substring(@href, string-length(@href) - 47), '.html#slide0')" /> </xsl:attribute> </slideshow> </xsl:template> </xsl:stylesheet> the idea copy contents of <p> tag expect <a> tag. changed condition on first apply-templates, don't have this. made things more readable me.
Comments
Post a Comment