transformation quits after third apply-templates
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 16
- Joined: Tue Aug 01, 2006 2:56 am
- Location: Chicago
transformation quits after third apply-templates
Post by gjledger2k »
Hi,
Having a problem with transforming code.
I need to select elements based on their (one) parent's attribute, and insert a unique attribute in each element.
Here is the xsl:
Here is some partial xml:
I know the answer is probably simple, so thanks for taking time to help.
Having a problem with transforming code.
I need to select elements based on their (one) parent's attribute, and insert a unique attribute in each element.
Here is the xsl:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<--here I need to recreate the cam element while inserting a namespace declaration-->
<xsl:template match="cam">
<cam xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<xsl:apply-templates/>
</cam>
</xsl:template>
<--listing is a child of cam, these represent records from a database; the only thing that changes is the member type. I want to add attributes to listing's children based on each unique member_type attribute.-->
<xsl:template match="listing[@MEMBER_TYPE='CPB']/COMPANY">
<company>
<xsl:attribute name="aid:pstyle">Head_Bronze</xsl:attribute>
<xsl:value-of select="."/>
</company>
<xsl:apply-templates/>
</xsl:template>
<--that worked fine, but instead of moving on to the next template, the transformation simply stops. The code below is not executed.-->
<xsl:template match="listing[@MEMBER_TYPE='CPG']/COMPANY">
<company>
<xsl:attribute name="aid:pstyle">Head_Gold</xsl:attribute>
<xsl:value-of select="."/>
</company>
<xsl:apply-templates/>
</xsl:template>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<cam>
<listing MEMBER_TYPE="CPB">
<FULL_NAME>Ms. Rebecca Sunny</FULL_NAME>
<COMPANY>ABC Company</COMPANY>
</listing>
<listing MEMBER_TYPE="CPG">
<FULL_NAME>Brook Farms</FULL_NAME>
<COMPANY>XYZ</COMPANY>
</listing>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: transformation quits after third apply-templates
I cannot reproduce the problem you mention, that is that the processing stops before matching the second COMPANY element. See below the complete files I tested with
and here it is the result with Saxon 6.5
Now, from your description you seem to want to copy the input and just add an aid:pstyle attribute on COMPANY... Check the stylesheet below:
The result is
Best Regards,
George
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<!--here I need to recreate the cam element while inserting a namespace declaration-->
<xsl:template match="cam">
<cam xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<xsl:apply-templates/>
</cam>
</xsl:template>
<!--listing is a child of cam, these represent records from a database; the only thing that changes is the member type. I want to add attributes to listing's children based on each unique member_type attribute.-->
<xsl:template match="listing[@MEMBER_TYPE='CPB']/COMPANY">
<company>
<xsl:attribute name="aid:pstyle">Head_Bronze</xsl:attribute>
<xsl:value-of select="."/>
</company>
<xsl:apply-templates/>
</xsl:template>
<!--that worked fine, but instead of moving on to the next template, the transformation simply stops. The code below is not executed.-->
<xsl:template match="listing[@MEMBER_TYPE='CPG']/COMPANY">
<company>
<xsl:attribute name="aid:pstyle">Head_Gold</xsl:attribute>
<xsl:value-of select="."/>
</company>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<cam>
<listing MEMBER_TYPE="CPB">
<FULL_NAME>Ms. Rebecca Sunny</FULL_NAME>
<COMPANY>ABC Company</COMPANY>
</listing>
<listing MEMBER_TYPE="CPG">
<FULL_NAME>Brook Farms</FULL_NAME>
<COMPANY>XYZ</COMPANY>
</listing>
</cam>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<cam xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
Ms. Rebecca Sunny
<company aid:pstyle="Head_Bronze">ABC Company</company>ABC Company
Brook Farms
<company aid:pstyle="Head_Gold">XYZ</company>XYZ
</cam>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<xsl:output method="xml"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- This is optional, just to have the aid namespace declaration on the root -->
<xsl:template match="cam">
<cam xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<xsl:apply-templates select="node() | @*"/>
</cam>
</xsl:template>
<xsl:template match="listing[@MEMBER_TYPE='CPB']/COMPANY">
<xsl:copy>
<xsl:attribute name="aid:pstyle">Head_Bronze</xsl:attribute>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="listing[@MEMBER_TYPE='CPG']/COMPANY">
<xsl:copy>
<xsl:attribute name="aid:pstyle">Head_Gold</xsl:attribute>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<?xml version="1.0" encoding="utf-8"?><cam xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<listing MEMBER_TYPE="CPB">
<FULL_NAME>Ms. Rebecca Sunny</FULL_NAME>
<COMPANY aid:pstyle="Head_Bronze">ABC Company</COMPANY>
</listing>
<listing MEMBER_TYPE="CPG">
<FULL_NAME>Brook Farms</FULL_NAME>
<COMPANY aid:pstyle="Head_Gold">XYZ</COMPANY>
</listing>
</cam>
George
George Cristian Bina
-
- Posts: 16
- Joined: Tue Aug 01, 2006 2:56 am
- Location: Chicago
Re: transformation quits after third apply-templates
Post by gjledger2k »
George,
Thanks so much. I did use your alternate code, and it worked great. I just had a few more bugs to work out before I could respond to your reply.
Thanks again.
Thanks so much. I did use your alternate code, and it worked great. I just had a few more bugs to work out before I could respond to your reply.
Thanks again.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service