Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It seems it's impossible to get an xlink:href to the referred keyword in a Keyword field using just the XSLT Mediator. </p> <p>To overcome this I created a .NET compound that "inflates" the extra keyword info in the XML. You'll have to place this compound just before the XSLT compound.</p> <p>Code: </p> <pre><code>namespace ContentManagement.TBB.Templates { [TcmTemplateTitle("Inflate Keyword Info")] public class GetExtendedComponent : TemplateBase { public override void Transform(Engine engine, Package package) { Initialize(engine, package); Component component = GetComponent(); XmlElement componentXml = component.ToXml(); XmlNamespaceManager ns = new XmlNamespaceManager(componentXml.OwnerDocument.NameTable); ns.AddNamespace("ns", component.Schema.NamespaceUri); ItemFields fields = new ItemFields(component.Content, component.Schema); InflateKeywords(fields, (XmlElement)componentXml.SelectSingleNode(String.Format("//ns:{0}", component.Schema.RootElementName), ns)); ItemFields metaFields = new ItemFields(component.Metadata, component.MetadataSchema); InflateKeywords(metaFields, (XmlElement)componentXml.SelectSingleNode("//ns:Metadata", ns)); Item xmlItem = package.CreateStringItem(ContentType.Component, componentXml.OuterXml); package.Remove(package.GetByName(Package.ComponentName)); package.PushItem(Package.ComponentName, xmlItem); } private void InflateKeywords(ItemFields fields, XmlElement element) { XmlNamespaceManager ns = new XmlNamespaceManager(element.OwnerDocument.NameTable); ns.AddNamespace("ns", element.NamespaceURI); Logger.Debug("NS: " + element.NamespaceURI); foreach (ItemField field in fields) { if (field is KeywordField) { KeywordField keywordField = (KeywordField)field; XmlNodeList nodes = element.SelectNodes(String.Format("./ns:{0}", keywordField.Name), ns); foreach (XmlNode node in nodes) { XmlElement kwelement = (XmlElement)node; Logger.Debug(String.Format("Keyword titel: {0}", keywordField.Value.Title)); Logger.Debug(String.Format("Keyword Element Value: {0}", kwelement.InnerText)); kwelement.SetAttribute("href", "http://www.w3.org/1999/xlink", keywordField.Values.First(v =&gt; v.Title.Equals(kwelement.InnerText)).Id); kwelement.SetAttribute("type", "http://www.w3.org/1999/xlink", "simple"); kwelement.SetAttribute("title", "http://www.w3.org/1999/xlink", kwelement.InnerText); } } else if (field is EmbeddedSchemaField) { EmbeddedSchemaField embedField = (EmbeddedSchemaField)field; XmlNodeList nodes = element.SelectNodes(String.Format("./ns:{0}", embedField.Name), ns); int i = 0; foreach (XmlNode node in nodes) { XmlElement embedElement = (XmlElement)node; InflateKeywords(embedField.Values[i], embedElement); i++; } } } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload