0

Hi every one, I have a question for xslt and xml output
I need to extract the text from creator or p with attribute class tags but if the creator and p with attribute class tags are the same I will not output the p tags. and each enclosed it with element name <bydesc>

XML input

<Article>
  <metadata>
    <creator>William Smith</creator>
    <creator>John Smith</creator>
 </metadata>
 <content
   <main>
   <p class="author">William Smith, John Smith</p>
   <p class="author">Jonathan Smith</p>
   </main>
</content>
<Article

>

XSL

<xsl:template name="BYLINE">
    <xsl:variable name="vByline">
       <xsl:apply-templates select="/Article/metadata/creator | /Article/content/main/p[@class='author' and not(text() = /
/dc_creator/text())]" mode="byline"/>
    </xsl:variable>
      <xsl:if test="string-length(normalize-space($vByline))!=0">
      <xsl:element name="BYLINE">
        <xsl:element name="bydesc">
        <xsl:value-of select="$vByline"/>
      </xsl:element>
      </xsl:element>
    </xsl:if>
  </xsl:template>

the produced OUTPUT

<BYLINE><bydesc>William SmithJohn SmithJonathan Smith</bydesc></BYLINE>

the OUTPUT should be

<BYLINE>
       <bydesc>William Smith</bydesc>
       <bydesc>John Smith</bydesc>
       <bydesc>Jonathan Smith</bydesc>
</BYLINE>

Again thank you for the bighelp.....thank you

Edited by perlnoob: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by xml_looser
0
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lnv="http://www.my.com">
	<xsl:output indent="yes" method="xml"/>
	<xsl:template match="/">
		<xsl:apply-templates select="Article/content/main"/>
	</xsl:template>
	<xsl:template match="main">
		<lnv:BYLINE>
			<xsl:apply-templates select="p"/>
		</lnv:BYLINE>
	</xsl:template>
	<xsl:template match="p">
		<xsl:call-template name="search">
			<xsl:with-param name="text" select="."/>
		</xsl:call-template>
	</xsl:template>
	<xsl:template name="search">
		<xsl:param name="text"/>
		<xsl:choose>
			<xsl:when test="contains($text,',')">
				<bydesc>
					<xsl:value-of select="normalize-space(substring-before($text,','))"/>
				</bydesc>
				<xsl:call-template name="search">
					<xsl:with-param name="text" select="normalize-space(substring-after($text,','))"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<bydesc>
					<xsl:value-of select="normalize-space($text)"/>
				</bydesc>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.