Matching children with namespace prefix
Posted: Fri May 14, 2010 12:34 am
Hi all,
I'm trying to parse an Adobe Acrobat PDF annotation file. This is my first transform, so forgive the ugliness. I'm just trying to get something to work.
Everything is working fine except for trying to match a particular child element that has a namespace prefix in its name.
Here's an excerpt of the source:
<item>
<title>Text Annotation by John Smith</title>
<guid>41-d4d32de6-0d69-4a60-afa2-9a987bfe9a88</guid>
<author>John Smith</author>
<description>yada yada</description>
<m:text xmlns:m="http://ns.adobe.com/xfdf/" color="#ffff00" creationdate="D:20100311155826-06'00'" date="D:20100311155850-06'00'" flags="print" icon="Comment" intent="Text" name="d4d32de6-0d69-4a60-afa2-9a987bfe9a88" opacity="1.000000" page="41" rect="464.074768,581.562805,484.074768,599.562805" reftype="R" subject="Sticky Note">
<m:popup open="yes" rect="612.000000,479.562805,792.000000,599.562805"/>
</m:text>
</item>
I'm pulling everything I need except for the "page" attribute which is part of the "m:text" element.
Here's my xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:m="http://ns.adobe.com/Acrobat/RSS/Reviews/">
<xsl:output method="text"></xsl:output>
<xsl:template match="/rss/channel">
<xsl:apply-templates select="item"></xsl:apply-templates>
</xsl:template>
<xsl:template match="item">
<xsl:if test="starts-with(title,'Text') or starts-with(title,'Highlight')">
<xsl:variable name="vDesc" select="substring-before(substring(description,287),'<')"></xsl:variable>
<xsl:variable name="vDesc" select="replace($vDesc,' ',' ')"></xsl:variable>
<xsl:variable name="vDesc" select="replace($vDesc,' ',' ')"></xsl:variable>
<xsl:variable name="vDesc" select="replace($vDesc,'	',' ')"></xsl:variable>
<xsl:variable name="vDesc" select="replace($vDesc,'"','^')"></xsl:variable>
<xsl:if test="string-length(normalize-space($vDesc)) > 0">
<xsl:value-of select="author"></xsl:value-of>
<xsl:text>	</xsl:text>
<xsl:value-of select="$vDesc"></xsl:value-of>
<xsl:text>	</xsl:text>
<xsl:apply-templates select="m:text"></xsl:apply-templates>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match = "m:text">
<xsl:text>	</xsl:text>
<xsl:value-of select="@page"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
When I single-step in oXygen's debugger, 'select="m:text" is not executing its corresponding match template. Does it matter than the m:text element has no actual value, just attributes?
I know that I'm brute-forcing this, but elegance must come at a later date. Any suggestions, elegant or otherwise will be greatly appreciated.
Regards,
John
I'm trying to parse an Adobe Acrobat PDF annotation file. This is my first transform, so forgive the ugliness. I'm just trying to get something to work.
Everything is working fine except for trying to match a particular child element that has a namespace prefix in its name.
Here's an excerpt of the source:
<item>
<title>Text Annotation by John Smith</title>
<guid>41-d4d32de6-0d69-4a60-afa2-9a987bfe9a88</guid>
<author>John Smith</author>
<description>yada yada</description>
<m:text xmlns:m="http://ns.adobe.com/xfdf/" color="#ffff00" creationdate="D:20100311155826-06'00'" date="D:20100311155850-06'00'" flags="print" icon="Comment" intent="Text" name="d4d32de6-0d69-4a60-afa2-9a987bfe9a88" opacity="1.000000" page="41" rect="464.074768,581.562805,484.074768,599.562805" reftype="R" subject="Sticky Note">
<m:popup open="yes" rect="612.000000,479.562805,792.000000,599.562805"/>
</m:text>
</item>
I'm pulling everything I need except for the "page" attribute which is part of the "m:text" element.
Here's my xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:m="http://ns.adobe.com/Acrobat/RSS/Reviews/">
<xsl:output method="text"></xsl:output>
<xsl:template match="/rss/channel">
<xsl:apply-templates select="item"></xsl:apply-templates>
</xsl:template>
<xsl:template match="item">
<xsl:if test="starts-with(title,'Text') or starts-with(title,'Highlight')">
<xsl:variable name="vDesc" select="substring-before(substring(description,287),'<')"></xsl:variable>
<xsl:variable name="vDesc" select="replace($vDesc,' ',' ')"></xsl:variable>
<xsl:variable name="vDesc" select="replace($vDesc,' ',' ')"></xsl:variable>
<xsl:variable name="vDesc" select="replace($vDesc,'	',' ')"></xsl:variable>
<xsl:variable name="vDesc" select="replace($vDesc,'"','^')"></xsl:variable>
<xsl:if test="string-length(normalize-space($vDesc)) > 0">
<xsl:value-of select="author"></xsl:value-of>
<xsl:text>	</xsl:text>
<xsl:value-of select="$vDesc"></xsl:value-of>
<xsl:text>	</xsl:text>
<xsl:apply-templates select="m:text"></xsl:apply-templates>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match = "m:text">
<xsl:text>	</xsl:text>
<xsl:value-of select="@page"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
When I single-step in oXygen's debugger, 'select="m:text" is not executing its corresponding match template. Does it matter than the m:text element has no actual value, just attributes?
I know that I'm brute-forcing this, but elegance must come at a later date. Any suggestions, elegant or otherwise will be greatly appreciated.
Regards,
John