Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-07
7
Medium Priority
?
774 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
Independent Software Vendors: 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

597 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