Solved

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

Posted on 2011-03-07
7
749 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When designing and editing page layouts in inDesign, fonts can become messy without the help of paragraph styles. How many times have you re-read through a document you created and noticed a sentence in the middle of a paragraph happened to be a dif…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now