Solved

When using XSL to transform XML for InDesign, How do I get the bold to output

Posted on 2011-03-07
7
751 Views
Last Modified: 2013-12-02
Thank you in advance for any help you can provide.

I have an XML document provided to me,  here's a snippet:

<?xml version="1.0" standalone="no"?>
<web-export>
<?whitespace-handling use-characters?>
<run-date>02/10/2011
<pub-code>UNG VP
<ad-type>CLS 6 Col Tab
<cat-code>Liner</cat-code>
<class-code>100</class-code>
<subclass-code>143</subclass-code>
<position-description>Notices</position-description>
<ad-number>0000146752-01</ad-number>
<start-date>02/10/2011</start-date>
<end-date>02/10/2011</end-date>
<line-count>6</line-count>
<run-count>1</run-count>
<customer-type>Transient</customer-type>
<account-number>151915</account-number>
<account-name>OREGON WCP STATEWIDE CLASS</account-name>
<addr-1>133 ENTERPRISE DRIVE </addr-1>
<addr-2> </addr-2>
<city>VERONA</city>
<state>WI</state>
<postal-code>53593</postal-code>
<country>USA</country>
<phone-number>6081111111</phone-number>
<fax-number></fax-number>
<url-addr></url-addr>
<email-addr></email-addr>
<pay-flag>N</pay-flag>
<ad-description>ATTENTIONDIABETICSWITHMEDICAREGETAFREETA</ad-description>
<order-source></order-source>
<order-status>Ready</order-status>
<payor-acct>151915</payor-acct>
<agency-flag>N</agency-flag>
<rate-note></rate-note>
<ad-content>
<b>ATTENTION DIABETICS </b>with Medicare.  Get a FREE Talking Meter and diabetic supplies at NO COST plus FREE home delivery!  Best of all, this meter eliminates painful finger pricking!  Call 1-888-667-5202 (wcan)</ad-content>
</ad-type>

I need to pull the data out of it that I need (not all) and apply formatting. I also don't want any repeating heads. I have accomplished this much with XSL.

What I can't get is the bold tag, within the ad-content tag to show up in the output.

Here is the XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
 
<!--Container Element -->
<xsl:element name="ad-type">
 
<!--Start loooping through XML data -->
 <xsl:for-each select="web-export/run-date/pub-code/ad-type">
     
<!--Set up elements. Do not ouput subclass-code and position-description dups-->
<subclass-code>
                  <xsl:value-of select='concat(subclass-code[not(.=preceding::subclass-code)], " ", position-description[not(.=preceding::position-description)])'/>
      </subclass-code>
     
<!--Carriage Return -->
      <xsl:text>&#13;</xsl:text>
     
<!--Add ad content -->
      <ad-content><xsl:value-of select="ad-content"/>
      </ad-content>

<!--Carriage Return -->    
     <xsl:text>&#13;</xsl:text>
     
</xsl:for-each>
</xsl:element>
</xsl:template>      
</xsl:stylesheet>

0
Comment
Question by:charthumser
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35062350
short answer:
replace this
<ad-content><xsl:value-of select="ad-content"/>
      </ad-content>
by this
<xsl:copy-of select="ad-content"/>

value of will only show the text nodes
copy-of will make a deep copy
     
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 125 total points
ID: 35062436
long answer,
it is always better to avoid for-each in favour of apply-templates if you can
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
        <!--Container Element -->
        <xsl:element name="ad-type">
            <!--Start loooping through XML data -->
            <xsl:apply-templates select="web-export/run-date/pub-code/ad-type"/>
        </xsl:element>
    </xsl:template>  
    
    <xsl:template match="ad-type">
        <!--Set up elements. Do not ouput subclass-code and position-description dups-->
        <subclass-code>
            <xsl:value-of select='concat(subclass-code[not(.=preceding::subclass-code)], " ", position-description[not(.=preceding::position-description)])'/>
        </subclass-code>
        
        <!--Carriage Return -->
        <xsl:text>&#13;</xsl:text>
        
        <!--Add ad content -->
        <ad-content><xsl:apply-templates select="ad-content/node()"/>
        </ad-content>
        
        <!--Carriage Return -->    
        <xsl:text>&#13;</xsl:text>
        
    </xsl:template>
    
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:charthumser
ID: 35062443
Wow. you've got to be kidding?!

Will that take care of italics and underlines too?

Actually, it's a bit flakey...it doesn't always end the bold.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35062461
it takes care of all the deeper nodes, italics and underline too

do you mean that your source is not well formed?
what is flakey?
0
 

Author Closing Comment

by:charthumser
ID: 35062464
wow.
0
 

Author Comment

by:charthumser
ID: 35062554
I meant that it wasn't always ending the bold where it was supposed to, it would bold the whole paragraph instead of just the word(s) between the tags.

Your revised code worked perfectly. I posted the flaky comment before I seen your code.

One more question, I have a carriage return after the subclass-code because without it, the Paragraph marker was applying the style from the next element. Any ideas?

I really appreciate the help, I was pulling my hair out on this one.

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35062584
OH, I see,
I have no clue about the paragraph marker
depends on how you look at the result
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question