Solved

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

Posted on 2011-03-07
7
757 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

685 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