In feeds, can multiple <content:encoded> elements exist inside an <item>? - rss

Precisely... can multiple <content:encoded> elements exist inside an <item> in a valid feed?
Full Story: I am modding the markup of my blog's RSS feeds for Google Currents, and for the app to display image galleries in articles as slideshows, the markup of my feed should look like this:
<rss version="2.0" ... xmlns:media="http://search.yahoo.com/mrss/">
...
<item>
<title>Item One</title>
<link>http://example.com/news/item-one</link>
<description>
<p>This is an example feed item</p>
</description>
...
<pubDate>Thu, 04 Aug 2011 19:41:00 GMT</pubDate>
<guid>http://example.com/news/item-one</guid>
<media:content height="84" type="image/jpeg" width="140" url="http://static.example.com/photo1.jpg">
<media:description>Caption for Photo 1</media:description>
</media:content>
<media:content height="100" type="image/jpeg" width="200" url="http://static.example.com/photo2.jpg">
<media:description>Caption for Photo 2</media:description>
</media:content>
<content:encoded><![CDATA[
<p>All the content goes here.</p>
<p>This is another line.</p>
]]></content:encoded>
...
</item>
...
</rss>
But due to the way my WordPress blog works, the galleries are shown within the article (which is usual), which means, the same happens in the RSS feeds as well. But the <media:content> element cannot be a sub-element of <content:encoded>.
So, I am wondering if I can do it like this and it'd still be valid RSS feed:
<rss version="2.0" ... xmlns:media="http://search.yahoo.com/mrss/">
...
<item>
<title>Item One</title>
<link>http://example.com/news/item-one</link>
<description>
<p>This is an example feed item</p>
</description>
...
<pubDate>Thu, 04 Aug 2011 19:41:00 GMT</pubDate>
<guid>http://example.com/news/item-one</guid>
<content:encoded><![CDATA[
<p>All the content goes here.</p>
]]></content:encoded>
<media:content height="84" type="image/jpeg" width="140" url="http://static.example.com/photo1.jpg">
<media:description>Caption for Photo 1</media:description>
</media:content>
<media:content height="100" type="image/jpeg" width="200" url="http://static.example.com/photo2.jpg">
<media:description>Caption for Photo 2</media:description>
</media:content>
<content:encoded><![CDATA[
<p>This is another line.</p>
]]></content:encoded>
...
</item>
...
</rss>
As you can see, I'd basically be splitting the <content:encoded> element into two, to give way for the slideshow markup. So, there'll be two <content:encoded> elements inside an <item>. Is that okay?

Having run my feed through W3C's Feed Validation Service, the answer seems to be "YES", multiple <content:encoded> elements can exist inside an <item> in a feed.

Related

XML -> list -> Data Frame in R with variable structure

This is my first post to Stack so please let me know if I haven't posted enough information. I have however, looked through many of the other answered questions and tried many of those solutions which as a result have ended me here.
I am having trouble getting the data out of a series of around 800 xml files. I would like the following data frame.
Model Species PubChemID out of "rdf:li*
Abiotrophia_defectiva_ATCC_49176 M_10fthf__91__c__93__ 122347
Abiotrophia_defectiva_ATCC_49176 M_10m3hddcaACP__91__c__93__ N/A
I can clean the rest of the URL out after its in a data frame for the PubChemID
From the following xml example.
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" xmlns:fbc="http://www.sbml.org/sbml/level3/version1/fbc/version2" xmlns:groups="http://www.sbml.org/sbml/level3/version1/groups/version1" level="3" version="1" fbc:required="false" groups:required="false">
<model metaid="Abiotrophia_defectiva_ATCC_49176" id="Abiotrophia_defectiva_ATCC_49176" name="Abiotrophia defectiva ATCC 49176" fbc:strict="true">
<notes>
<body xmlns="http://www.w3.org/1999/xhtml">
<div>
<h1>Abiotrophia_defectiva_ATCC_49176</h1>
<h2>Description</h2>
<p>This is a metabolism reconstruction of Abiotrophia defectiva ATCC 49176</p>1.03<p>Authors: Stefania Magnusdottir, Almut Heinken, Laura Kutt, Dmitry A. Ravcheev, Eugen Bauer, Alberto Noronha, Kacy Greenhalgh, Christian Jaeger, Joanna Baginska, Paul Wilmes, Ronan M.T. Fleming, and Ines Thiele.</p>
<h3>Draft information</h3>
<p>
<ul>
<li> PubSEED ID: Abiotrophia defectiva ATCC 49176 (592010.4)</li>
<li> Draft reconstruction ID: Seed592010_4_124632</li>
<li> Draft platform: ModelSEED</li>
<li> Draft created: 7/1/2014</li>
</ul>
</p>
<p>This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.</p>
<p>When using this model in your research works, please cite: Magnusdottir et al., Generation of genome-scale metabolic reconstructions for 773 members of the human gut microbiota, Nat Biotechnol, 2016.</p></div>
</body>
</notes>
<annotation>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:vCard4="http://www.w3.org/2006/vcard/ns#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
<rdf:Description rdf:about="#Abiotrophia_defectiva_ATCC_49176">
<bqbiol:is>
<rdf:Bag>
<rdf:li rdf:resource="http://identifiers.org/taxonomy/592010"/>
</rdf:Bag>
</bqbiol:is>
</rdf:Description>
</rdf:RDF>
</annotation>
<listOfUnitDefinitions>
<unitDefinition id="mmol_per_gDW_per_hr">
<listOfUnits>
<unit kind="mole" exponent="1" scale="-3" multiplier="1"/>
<unit kind="gram" exponent="-1" scale="0" multiplier="1"/>
<unit kind="second" exponent="-1" scale="0" multiplier="3600"/>
</listOfUnits>
</unitDefinition>
</listOfUnitDefinitions>
<listOfCompartments>
<compartment metaid="c" id="c" name="Cytoplasm" constant="false"/>
<compartment metaid="e" id="e" name="Extracellular" constant="false"/>
</listOfCompartments>
<listOfSpecies>
<species metaid="M_10fthf__91__c__93__" id="M_10fthf__91__c__93__" name="10-Formyltetrahydrofolate" compartment="c" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false" fbc:charge="-2" fbc:chemicalFormula="C20H21N7O7">
<annotation xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:vCard4="http://www.w3.org/2006/vcard/ns#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
<rdf:Description rdf:about="#M_10fthf__91__c__93__">
<bqbiol:is>
<rdf:Bag>
<rdf:li rdf:resource="http://identifiers.org/hmdb/HMDB00972"/>
<rdf:li rdf:resource="http://identifiers.org/kegg.compound/C00234"/>
<rdf:li rdf:resource="http://identifiers.org/pubchem.compound/122347"/>
</rdf:Bag>
</bqbiol:is>
</rdf:Description>
</rdf:RDF>
</annotation>
</species>
<species metaid="M_10m3hddcaACP__91__c__93__" id="M_10m3hddcaACP__91__c__93__" name="10-methyl-3-hydroxy-dodecanoyl-ACP" compartment="c" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false" fbc:charge="-1" fbc:chemicalFormula="C24H45N2O9PRS"/>
<species metaid="M_10m3hundecACP__91__c__93__" id="M_10m3hundecACP__91__c__93__" name="10-methyl-3-hydroxy-undecanoyl-ACP" compartment="c" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false" fbc:charge="-1" fbc:chemicalFormula="C23H43N2O9PRS"/>
<species metaid="M_10m3oddcaACP__91__c__93__" id="M_10m3oddcaACP__91__c__93__" name="10-methyl-3-oxo-dodecanoyl-ACP" compartment="c" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false" fbc:charge="-1" fbc:chemicalFormula="C24H43N2O9PRS"/>
</listOfSpecies>
</model>
</sbml>
I have been successful in converting to a list in r and calling the first element that should apply to the other 800 xml
library(xml2)
list <- xmlToList("StackExample.xml")
list[["model"]][["notes"]][["body"]][["div"]][["h1"]]
I also can get all of the species out but the fact that some of the nodes contain more hierarchy has got me a bit baffled.
species.list <- list$model$listOfSpecies
specieslist <- lapply(species.list, '[[', 1)
How does one add an if/else type function into "lapply" so that it looks for "/rdf:resources" in the additional hierarchy?
Lastly, I am pretty sure that applying whatever script to the remainder of the files should be doable.
Thanks

Set background image of div in xslt file from sitecore image item

As the question states I'm trying to set a background image in XSL file for a Sitecore Email component.
If I hard code a variable with the image source and then set the Div's background using Style then I can see my div with the background set.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sc="http://www.sitecore.net/sc"
xmlns:dot="http://www.sitecore.net/dot"
exclude-result-prefixes="dot sc">
<!-- output directives -->
<xsl:output method="html" indent="no" encoding="UTF-8" />
<!-- parameters -->
<xsl:param name="lang" select="'en'"/>
<xsl:param name="id" select="''"/>
<xsl:param name="sc_item"/>
<xsl:param name="sc_currentitem"/>
<!-- variables -->
<!-- Uncomment one of the following lines if you need a "home" variable in you code -->
<!--<xsl:variable name="home" select="sc:item('/sitecore/content/home',.)" />-->
<!--<xsl:variable name="home" select="/*/item[#key='content']/item[#key='home']" />-->
<!--<xsl:variable name="home" select="$sc_currentitem/ancestor-or-self::item[#template='site root']" />-->
<xsl:variable name="backgroundurl">-/media/Images/go-ape-forest-banner-background.ashx</xsl:variable>
<!-- entry point -->
<xsl:template match="*">
<xsl:apply-templates select="$sc_item" mode="main"/>
</xsl:template>
<!--==============================================================-->
<!-- main -->
<!--==============================================================-->
<xsl:template match="*" mode="main">
<div style="background:url({$backgroundurl}); background-repeat:no-repeat; background-size:100% 100%; height:200px; border-radius: 25px; border: 2px solid black; padding-left: 20px;padding-right: 20px;">
</div>
</xsl:template>
</xsl:stylesheet>
As you can see from the screen shot above, this works so far as the image is displayed as the div's background image, but is not what I'm after, the background image should be set according to the Sitecore Item, In this case the Items background image field and not a hard coded variable.
I have access to various items from the components template. In this case we have the following fields:
Logo (Image)
Icon (Image)
Background (Image)
Headline (Single-Line Text)
Icon Text (Single-Line Text)
I can access these items on the page using the following sitecore controls:
<sc:image field="logo"/>
<sc:image field="icon" />
<sc:image field="background" />
<sc:text field="headline"/>
<sc:text field="icon text"/>
If I add the above onto my xsl page they render correctly as can bee seen from screen shot below:
I want to take the background image field and get the src value from it and then set my div's background to this value.
Any idea's how this could/should be done?
Regards,
Comic Coder
EDIT:
I noticed something funny that you may be able to help me understand what is happening.
When I use the following in my XSLT file:
<img src="{sc:fld('background',.,'src')}" alt="{sc:fld('background',.,'alt')}" />
And inspect the source code output i get the following rendered on the page.
<img src="" alt="go-ape-forest-banner-background" sc-part-of="placeholder rendering" class="scEnabledChrome">
I can see the src field is empty and this is a problem. This is the method that is provided by sitecore at the following link on the sitecore SDN
Assessing Field Values in Sitecore
When I use:
<img src="{sc:field('background',.,'src')}" alt="{sc:fld('background',.,'alt')}" />
Notice the fld on the src field has changed to field now and i get the following when i inspect the source.
<img src="<input id='fld_B9ACE161A86D474390C7DA8308D79278_4C5D9258F7CF44B8A073A078CAEC08B0_en_1_00a4e02d3315484a8da1a756f2ef2d69_6759' class='scFieldValue' name='fld_B9ACE161A86D474390C7DA8308D79278_4C5D9258F7CF44B8A073A078CAEC08B0_en_1_00a4e02d3315484a8da1a756f2ef2d69_6759' type='hidden' value="&lt;image mediapath=&quot;&quot; alt=&quot;go-ape-forest-banner-background&quot; width=&quot;600&quot; height=&quot;108&quot; hspace=&quot;2&quot; vspace=&quot;2&quot; showineditor=&quot;&quot; usethumbnail=&quot;&quot; src=&quot;&quot; mediaid=&quot;{EE47E80F-DE1E-4FDD-B5D8-ACA473B52A9C}&quot; /&gt;" /><code id="fld_B9ACE161A86D474390C7DA8308D79278_4C5D9258F7CF44B8A073A078CAEC08B0_en_1_00a4e02d3315484a8da1a756f2ef2d69_6759_edit" sc_parameters="format" type="text/sitecore" chromeType="field" scFieldType="image" class="scpm" kind="open">{"commands":[{"click":"chrome:field:editcontrol({command:\"webedit:chooseimage\"})","header":"Choose Image","icon":"/sitecore/shell/themes/standard/custom/16x16/photo_landscape2.png","disabledIcon":"/temp/photo_landscape2_disabled16x16.png","isDivider":false,"tooltip":"Choose an image.","type":""},{"click":"chrome:field:editcontrol({command:\"webedit:editimage\"})","header":"Properties","icon":"/sitecore/shell/themes/standard/custom/16x16/photo_landscape2_edit.png","disabledIcon":"/temp/photo_landscape2_edit_disabled16x16.png","isDivider":false,"tooltip":"Modify image appearance.","type":""},{"click":"chrome:field:editcontrol({command:\"webedit:clearimage\"})","header":"Clear","icon":"/sitecore/shell/themes/standard/custom/16x16/photo_landscape2_delete.png","disabledIcon":"/temp/photo_landscape2_delete_disabled16x16.png","isDivider":false,"tooltip":"Remove the image.","type":""},{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"Edit the related item","icon":"/temp/iconcache/office/16x16/cubes.png","disabledIcon":"/temp/cubes_disabled16x16.png","isDivider":false,"tooltip":"Edit the related item in the Content Editor.","type":"common"},{"click":"chrome:rendering:personalize({command:\"webedit:personalize\"})","header":"Personalize","icon":"/temp/iconcache/office/16x16/users_family.png","disabledIcon":"/temp/users_family_disabled16x16.png","isDivider":false,"tooltip":"Create or edit personalization for this component.","type":"sticky"},{"click":"chrome:rendering:editvariations({command:\"webedit:editvariations\"})","header":"Edit variations","icon":"/temp/iconcache/office/16x16/windows.png","disabledIcon":"/temp/windows_disabled16x16.png","isDivider":false,"tooltip":"Edit the variations.","type":"sticky"}],"contextItemUri":"sitecore://master/{B9ACE161-A86D-4743-90C7-DA8308D79278}?lang=en&ver=1","custom":{},"displayName":"Background","expandedDisplayName":null}</code><img src="/sitecore/shell/-/media/Images/go-ape-forest-banner-background.ashx?h=108&amp;la=en&amp;w=600&amp;hash=B3D30A69E02A5C0AC47D2475FF85DFA166768C40" hspace="2" vspace="2" alt="go-ape-forest-banner-background" width="600" height="108" /><code class="scpm" type="text/sitecore" chromeType="field" kind="close"></code>" alt="go-ape-forest-banner-background" sc-part-of="placeholder rendering" class="scEnabledChrome">
I have also asked a question that is relevant to this problem regarding the use of the XSLHelper.fld method which is not working as expected. You can see the question here:
Sitecore XSLHelper.fld Method not working as expected
Before I answer, I have to say that I would highly recommend that you stop using XSLT. Future maintainers of your code (including yourself) will thank you if you move to MVC. If you want to avoid the need to compile, you can use View renderings.
The following code was adapted from the old presentation component reference doc for Sitecore 6. I haven't tested it on 8 as I have no desire to touch XSLT again, but I think it should still work.
<xsl:variable name="mediaid" select="sc:fld('Background',$sc_currentitem,'mediaid')" />
<xsl:if test="$mediaid">
<xsl:variable name="mediaitem" select="sc:item($mediaid,.)" />
<xsl:if test="$mediaitem">
<div style="background:url({sc:GetMediaUrl($mediaitem)}); background-repeat:no-repeat; background-size:100% 100%; height:200px; border-radius: 25px; border: 2px solid black; padding-left: 20px;padding-right: 20px;">
</xsl:if>
</xsl:if>
Update in response to additional info
The article you linked to is out-of-date. There is no longer a src attribute in image fields. If you just select an image you will see something like this if you view the raw value of the field:
<image mediaid="{094AED03-02E7-4868-80CB-19926661FB77}" />
If you modify the properties of the image (e.g. set the alt text or dimensions) you will see something like this:
<image mediaid="{094AED03-02E7-4868-80CB-19926661FB77}" alt="alt text" height="" width="150" hspace="" vspace="" />
To get the URL, you need to use the mediaid property like I showed above.

How to make xsl show only images/captions from xml

I have two images in my xml:
<?xml version="1.0" encoding="UTF-8"?>
<description>
<title>Letter from Waldemar Schultze to Jennie Schultze</title>
<creator type="author">
<name type="personal">Schultze, Waldemar</name>
</creator>
<date>1943-06-30</date>
<source>Special Collections and University Archives, W. E. B. Du Bois Library,
University of Massachusetts Amherst.</source>
<citation>Robert and Waldemar Schultze Papers (MS 528). Special Collections and
University Archives, W.E.B. Du Bois Library, University of
Massachusetts Amherst.</citation>
</description>
<text>
<header type="letterhead">
<imageGroup>
<image xlink:href="mums528-i001-001.png"/>
<caption>page 1</caption>
</imageGroup>
<imageGroup>
<image xlink:href="mums528-i001-002.png"/>
<caption>page 2</caption>
</imageGroup>
<organization>Unites States Disciplinary Barracks</organization>
<location>Fort Leavenworth, Kansas</location>
<date format="M/DD/YY">6/30/43</date>
<recipient>
<name type="personal">Mrs. W.J. Schultze</name>
<address>875 Richmond Av., Buffalo, N.Y.</address>
<relation>Mother</relation>
</recipient>
</header>
<body>
<salutation>Dear Mother,</salutation>
<p><line>This is the first letter I have had</line>
<line>an opportunity to write you since leaving Fort</line>
<line>Jay, and I know you must be anxious to hear from me.</line></p>
<p><line>Bob and I are both feeling as well as</line>
<line>can be expected considering our present cir-</line>
<line>cumstances. We both have high blood</line>
<line>pressure, mine has been 160/100 for the past</line>
<line>2 days, and Bob's 158/96, but my sinus</line>
<line>infection has not caused me quite so much</line>
<line>trouble since leaving N.Y. State. I believe</line>
<line>the air is dryer here and is responsible</line>
<line>for any alleviation that has taken place.</line></p>
<p><line>While a prisoner here remains in their</line>
<line>so-called 1st grade, he is able to write</line>
<line>twice a week, in second grade once a week,</line>
<line>and in third grade once a month. These</line>
<line>grades refer to classifications that ostensibly</line>
<line>are for conduct while here. It is quite possible</line>
<line>to lose a conduct rating, as I understand it,</line>
<line>by not having a perpetually rusting tin cup polished</line>
<pb n="2"/>
<line>brightly for daily inspection, although the tin plating long ago dis-</line>
<line>appeared and the cup is rusty again within 2 hours after wetting.</line></p>
<p><line>The food here is good and is well-cooked,</line>
<line>with one exception, the gravy, which is nothing but</line>
<line>flour, water, and bacon grease, Strangely enough, how-</line>
<line>ever, no condiments, not even salt, are provided on</line>
<line>the table, to the detriment of otherwise very good</line>
<line>meals. While meat here is unrationed and is plentiful,</line>
<line>toilet paper; believe it or not, is rationed. A</line>
<line>5¢ roll must last a prisoner 45 days, or else -- ?</line>
<line>Perhaps, however, a prisoner can purchase additional</line>
<line>if it should be necessary.</line></p>
<p><line>Please see that my subscriptions are transferred</line>
<line>here as soon as possible from Fort Jay. Give Florence</line>
<line>and Helen my regards, and thank Joe for his</line>
<line>efforts in my behalf in managing my business.</line>
<line>Find out from Joe how tube deliveries are at the</line>
<line>present time, first to satisfy my curiosity; and</line>
<line>also let me know if you are receiving your</line>
<line>remittance regularly from him. If he is not</line>
<line>taking care of your support in accordance with</line>
<line>the instructions I left him, I wish to know it,</line>
<line>so I can write, and correct the matter.</line>
<line>You can tell Joe to subscribe to Electronics</line>
<line>magazine for me and send it to this address</line>
<line>direct from the publisher. He should also have a copy</line>
<line>of Palmer's "Calculus for Home Study," sent me by the publisher,</line>
<line>whose name he can obtain from Ulbrichs. In future letters I'll</line>
<line>copy the "Prisoner's Handbook" issued here, and the</line>
<line>contents of the detached letter form stub.</line>
</p>
<valediction>Love, Waldemar</valediction>
</body>
</text>
I want to transform the xml so that ONLY the images and their captions are displayed. Here's my xsl:
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="letter.css"/>
<title>Letter</title>
</head>
<body>
<div>
<xsl:apply-templates/>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="//imageGroup">
<xsl:if test="//imageGroup">
<div class="image">
<xsl:for-each select="//imageGroup">
<img src="{image/#xlink:href}"/>
<span class="caption"><xsl:value-of select="caption"/></span>
</xsl:for-each>
</div>
</xsl:if>
</xsl:template>
The problem is, my output still shows all the text, and my images are doubled. How do I fix it without changing anything in the xml?
Replace the <xsl:apply-templates/> with <xsl:apply-templates select="//imageGroup"/>, then of course your template for those elements should not employ any for-each, but simply display each image, e.g.
<xsl:template match="imageGroup">
<img src="{image/#xlink:href}"/>
<span class="caption"><xsl:value-of select="caption"/></span>
</xsl:template>

How to output an IMG tag from XML using XSLT

Here is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<Collection>
<Content>
<ID>2779</ID>
<Type>Content</Type>
<Title>Article One</Title>
<QuickLink>/template.aspx?id=2779</QuickLink>
<Teaser />
<Html>
<root>
<NewsArticle>
<artTitle>The Comprehensive Breast Center: Quality Care on the Fast Track</artTitle>
<artThumb>
<img alt="Thumb Article One" src="/uploadedImages/Test/News/artOne.png?n=5954" />
</artThumb>
<artFull />
<releaseDate />
<contactName />
<contactPhone />
<contactEmail />
<artTeaser>The National Cancer Institute estimates that a woman in the United States has a 1 in 8 chance of developing invasive breast cancer</artTeaser>
<artText>
<p>The Comprehensive Breast Center: Quality Care on
the Fast Track</p>
<p>
How do I display the IMG tag from my XML above to an HTML document using XSLT
Something like this should do the trick:
<xsl:template match="/">
<xsl:for-each select="Collection/Content">
<xsl:copy-of select="Html/root/NewsArticle/artThumb/node()"/>
</xsl:for-each>
</xsl:template>
I should note that this assumes you're getting this from an Ektron collection -- assumption made based on your tagging of this question. This will display the image from each content block in the collection. If you want just the image from the first content block of the collection, you could remove the for-each and instead use something like this:
<xsl:template match="/">
<xsl:copy-of select="Collection/Content/Html/root/NewsArticle/artThumb/node()"/>
</xsl:template>
Also, it works either way, but i removed the slash from the front of the select on the for-each. Seemed redundant since the code is in a template that already matches on "/".
UPDATE
Some of that can be done in the workarea -- it allows you to set the css class, though I'm not sure if you can set the title attribute of an image. Here's how you could do that via XSLT. In this case, you can't copy the node whole-sale:
<xsl:template match="/">
<xsl:for-each select="Collection/Content">
<xsl:variable name="imageSrc" select="Html/root/NewsArticle/artThumb/img/#src" />
<xsl:variable name="imageId">
<xsl:text>NewsArticle_</xsl:text>
<xsl:value-of select="ID" />
<xsl:text>_image</xsl:text>
</xsl:variable>
<xsl:variable name="contentTitle" select="Html/root/NewsArticle/artTitle" />
<img id="{ $imageId }" class="myCssClass" title="{ $contentTitle }" alt="{ $contentTitle }" src="{ $imageSrc }" />
</xsl:for-each>
</xsl:template>
(Updated again - appears i misread your comment. Thanks, #MathiasMüller!)
When assigning ids to elements like this, I prefer to use a little more than just the content id. In this case, by using "NewsArticle_{Content ID}image", I allow for a container div to use an id "NewsArticle{Content Id}" if it is needed in the future without colliding with the image ids.
How do i assign a title and an alt from artTitle and also a class and id?
Building upon the answer given by #BrianOliver, this is how you output an img element whose "title" attribute reflects the content of artTitle from your input XML - the same for ID.
I assume that by "an alt from artTitle" you mean that the text content of img/#alt should also come from the artTitle element.
<xsl:template match="/">
<xsl:for-each select="Collection/Content">
<xsl:variable name="imageSrc" select="Html/root/NewsArticle/artThumb/img/#src" />
<!--xsl:variable name="imageAlt" select="Html/root/NewsArticle/artThumb/img/#alt" /-->
<xsl:variable name="imageId" select="ID"/>
<xsl:variable name="imageTitle" select="Html/root/NewsArticle/artTitle"/>
<img id="{$imageId}" class="myCssClass" title="{$imageTitle}" alt="{ $imageTitle}" src="{$imageSrc}"/>
</xsl:for-each>
</xsl:template>
However, I am not sure where the class attribute should come from.

XSL transformatiotion to XForms from simple XML file and applying CSS

I am transforming some simple XML document into XForms and I am trying to add some style to the final result. I am using the XSLTForms implementation and I am pointing to a local CSS file (Twitter's bootstrap). So the XML file looks like that:
<structure>
<part class="Container" id="container">
<part class="Button" id="b1"/>
</part>
</structure>
<style>
<property part-name="b1" name="label">Submit</property>
</style>
My XSLT that transforms these parts to XForms document:
<xsl:key name="buttonLabels" match="property[#name='label']" use="#part-name"/>
<xsl:template match="part[#class='Button']"><!-- [key('buttonActions', #id)]-->
<xsl:element name="xf:trigger">
<xsl:attribute name="id">
<xsl:value-of select="#id | #size | #style"/>
</xsl:attribute>
<xsl:element name="xf:label">
<xsl:value-of select="key('buttonLabels', #id)"/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="part[#class='Container']">
<xsl:element name="div">
<xsl:attribute name="class">container</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Now, this produces: (which is fine for what I need currently)
<div class="container">
<xf:trigger id="b1">
<xf:label>Submit</xf:label>
</xf:trigger>
</div>
But I'd like to add some style rules to this <xf:trigger>. The thing is that when it gets transformed into html elements, the structure is
|_span
|_span
|_button
|_span (for the label)
So I am not sure how to make the XSLT transformation, so that it inserts let's say class="btn-danger" attribute into the <button> tag.
In other words, I need to get something like that in the final Html: (currently I get it, but without the class="btn-danger" in the button tag)
<span id="b1">
<span>
<button type="button" class="btn-danger">
<span id="xsltforms-mainform-label-2_6_2_4_3_" class="xforms-label">Submit</span>
</button>
</span>
</span>
Besides, I tried with adding an <xsl:attribute name="class">btn-danger</xsl:attribute> in the template for the xf:trigger, but that inserts the attribute at the first span element.
Any ideas? Thanks in advance!
UPDATE:
The XSLT responsible for transforming the xforms:trigger element to html elements can be found on this link - http://bpaste.net/show/c42CtcIcjbsI6GFGWK2q/
But I don't want to edit the XSLTForms implementation, but rather find a workaround, so that I can specify the style of my buttons from my XML file.
For example:
<structure>
<part class="Container" id="container">
<part class="Button" id="b1"/>
</part>
</structure>
<style>
<property part-name="b1" name="label">Submit</property>
<property part-name="b1" name="style">btn-danger</property>
</style>
So here, I am matching the part-name and saying that I want the button with id="b1" to have css style rules for btn-danger for example. But if I have another button and there is no style rule for it, it should have default appearance. Hope that's clear.
You cannot add a class attribute directly to the button element generated by XSLTForms.
But instead of it, you can define a CSS rule that applies to it this way:
#myclass button {
color: red;
}
and use the class in the trigger:
<xf:trigger class="myclass >
The same for every XForms control. Just take a look to the browser inspector to see the generated controls.

Resources